Browse Source

working project list

master
Richard Cagle 1 year ago
parent
commit
168745bba9
13 changed files with 315 additions and 30 deletions
  1. 4
    0
      .gitignore
  2. 75
    0
      .rubocop.yml
  3. 1
    1
      .ruby-version
  4. 12
    2
      Gemfile
  5. 94
    1
      Gemfile.lock
  6. 24
    0
      app.rb
  7. 62
    0
      basecamp.rb
  8. 0
    13
      generate.rb
  9. 0
    0
      public/favicon.ico
  10. 0
    13
      server.rb
  11. 7
    0
      views/index.erb
  12. 31
    0
      views/layout.erb
  13. 5
    0
      views/oauth.erb

+ 4
- 0
.gitignore View File

@@ -0,0 +1,4 @@
/.env
/basecamp_tokens.json

.DS_Store

+ 75
- 0
.rubocop.yml View File

@@ -0,0 +1,75 @@
inherit_mode:
merge:
- Exclude

Layout/EmptyLinesAroundAccessModifier:
EnforcedStyle: only_before

Layout/ExtraSpacing:
AllowForAlignment: false

Layout/IndentationConsistency:
EnforcedStyle: indented_internal_methods

Layout/LineLength:
Enabled: false

Metrics:
Enabled: false

Style/AndOr:
Enabled: false

Style/HashEachMethods:
Enabled: false

Style/HashTransformKeys:
Enabled: false

Style/HashTransformValues:
Enabled: false

Style/ClassAndModuleChildren:
Enabled: false

Style/ConditionalAssignment:
Enabled: false

Style/DocumentationMethod:
Enabled: false

Style/EmptyMethod:
Enabled: false

Style/FormatStringToken:
Enabled: false

Style/GuardClause:
Enabled: false

Style/IfInsideElse:
Enabled: false

Style/IfUnlessModifier:
Enabled: false

Style/NumericLiterals:
Enabled: false

Style/SafeNavigation:
Enabled: false

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes

Style/SymbolArray:
Enabled: false

Style/WordArray:
Enabled: false

Style/Documentation:
Enabled: false

+ 1
- 1
.ruby-version View File

@@ -1 +1 @@
2.7.0
2.6.5

+ 12
- 2
Gemfile View File

@@ -2,8 +2,18 @@

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

ruby "2.7.0"
ruby "2.6.5"

gem "oauth2", "~> 1.4"

gem "sinatra", "~> 2.0"

gem "sinatra-contrib", "~> 2.0"

gem "rubocop", "~> 0.80.1"

gem "erb_lint", "~> 0.0.30"

gem "dotenv", "~> 2.7"

+ 94
- 1
Gemfile.lock View File

@@ -1,28 +1,121 @@
GEM
remote: https://rubygems.org/
specs:
actionview (6.0.2.1)
activesupport (= 6.0.2.1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activesupport (6.0.2.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2)
ast (2.4.0)
backports (3.16.1)
better_html (1.0.14)
actionview (>= 4.0)
activesupport (>= 4.0)
ast (~> 2.0)
erubi (~> 1.4)
html_tokenizer (~> 0.0.6)
parser (>= 2.4)
smart_properties
builder (3.2.4)
concurrent-ruby (1.1.6)
crass (1.0.6)
dotenv (2.7.5)
erb_lint (0.0.30)
activesupport
better_html (~> 1.0.7)
html_tokenizer
rainbow
rubocop (~> 0.51)
smart_properties
erubi (1.9.0)
faraday (1.0.0)
multipart-post (>= 1.2, < 3)
html_tokenizer (0.0.7)
i18n (1.8.2)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.4)
jwt (2.2.1)
loofah (2.4.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mini_portile2 (2.4.0)
minitest (5.14.0)
multi_json (1.14.1)
multi_xml (0.6.0)
multipart-post (2.1.1)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
nokogiri (1.10.8)
mini_portile2 (~> 2.4.0)
oauth2 (1.4.4)
faraday (>= 0.8, < 2.0)
jwt (>= 1.0, < 3.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
parallel (1.19.1)
parser (2.7.0.3)
ast (~> 2.4.0)
rack (2.2.2)
rack-protection (2.0.8.1)
rack
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
rainbow (3.0.0)
rexml (3.2.4)
rubocop (0.80.1)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.7.0.1)
rainbow (>= 2.2.2, < 4.0)
rexml
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
ruby-progressbar (1.10.1)
ruby2_keywords (0.0.2)
sinatra (2.0.8.1)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.8.1)
tilt (~> 2.0)
sinatra-contrib (2.0.8.1)
backports (>= 2.8.2)
multi_json
mustermann (~> 1.0)
rack-protection (= 2.0.8.1)
sinatra (= 2.0.8.1)
tilt (~> 2.0)
smart_properties (1.15.0)
thread_safe (0.3.6)
tilt (2.0.10)
tzinfo (1.2.6)
thread_safe (~> 0.1)
unicode-display_width (1.6.1)
zeitwerk (2.2.2)

PLATFORMS
ruby

DEPENDENCIES
dotenv (~> 2.7)
erb_lint (~> 0.0.30)
oauth2 (~> 1.4)
rubocop (~> 0.80.1)
sinatra (~> 2.0)
sinatra-contrib (~> 2.0)

RUBY VERSION
ruby 2.7.0p0
ruby 2.6.5p114

BUNDLED WITH
2.1.4

+ 24
- 0
app.rb View File

@@ -0,0 +1,24 @@
# frozen_string_literal: true

require "dotenv/load"
require "bundler/setup"
require "json"
require "sinatra"
require "sinatra/reloader" if development?

require_relative "basecamp"

b3 = Basecamp3.new

get "/" do
if b3.authenticated?
erb :index, locals: { b3: b3 }
else
erb :oauth, locals: { authorize_url: b3.authorize_url }
end
end

get "/oauth-token" do
b3.get_access_token(params["code"])
redirect "/"
end

+ 62
- 0
basecamp.rb View File

@@ -0,0 +1,62 @@
# frozen_string_literal: true

require "json"
require "oauth2"

class Basecamp3
attr_accessor :client, :token, :api_url, :auth_info, :authorize_url

def initialize
@client = OAuth2::Client.new(
ENV["BASECAMP_CLIENT_ID"],
ENV["BASECAMP_CLIENT_SECRET"],
site: "https://launchpad.37signals.com",
authorize_url: "/authorization/new",
token_url: "/authorization/token"
)

@authorize_url = @client.auth_code.authorize_url(redirect_uri: ENV["REDIRECT_URL"], type: "web_server")

if File.exist?("basecamp_tokens.json")
token_data = JSON.parse(File.read("basecamp_tokens.json"))
@token = OAuth2::AccessToken.from_hash(@client, token_data)
@token = @token.refresh if @token.expired?

@auth_info = authorization
@api_url = @auth_info["accounts"][0]["href"]
end
end

def authenticated?
return false unless @token

@token = @token.refresh if @token.expired?
true
end

def get_access_token(code)
access_token_response = @client.auth_code.get_token(code, type: "web_server", redirect_uri: ENV["REDIRECT_URL"])

token_hash = {
access_token: access_token_response.token,
refresh_token: access_token_response.refresh_token,
expires_in: access_token_response.expires_in,
expires_at: access_token_response.expires_at
}

File.write("basecamp_tokens.json", JSON.pretty_generate(token_hash))
end

def teams
@token.get("#{@api_url}/teams.json").parsed
end

def projects
@token.get("#{@api_url}/projects.json").parsed
end

private
def authorization
@token.get("/authorization.json").parsed
end
end

+ 0
- 13
generate.rb View File

@@ -1,13 +0,0 @@
require 'oauth2'
require 'erb'

client = OAuth2::Client.new(
'eb34f9ce358bbf11a575455ba4c03ecfa2798392',
'7df1c034dc19ed8d92da1592d842257b1d178d0f',
site: 'https://launchpad.37signals.com',
authorize_url: '/authorization/new',
token_url: '/authorization/token'
)

client.auth_code.authorize_url(redirect_uri: 'http://localhost:5678', type: 'web_server')
client.auth_code.get_token('7fbaafc2', type: 'web_server', redirect_uri: 'http://localhost:5789')

+ 0
- 0
public/favicon.ico View File


+ 0
- 13
server.rb View File

@@ -1,13 +0,0 @@
require 'socket'
server = TCPServer.new 5678

while session = server.accept
request = session.gets

session.print "HTTP/1.1 200\r\n" # 1
session.print "Content-Type: text/html\r\n" # 2
session.print "\r\n" # 3
session.print request.inspect

session.close
end

+ 7
- 0
views/index.erb View File

@@ -0,0 +1,7 @@
<h3 class="has-text-centered">This is <%= b3.auth_info["accounts"][0]["name"] %></h3>

<ul>
<% b3.projects.each do |project| %>
<li><%= project["name"] %></li>
<% end %>
</ul>

+ 31
- 0
views/layout.erb View File

@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

<title>Basecamp - The Big Picture</title>

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.8.0/css/bulma.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,400i,700,700i&display=swap">

<style type="text/css">
body {
font-family: "Lato", sans-serif;
}
</style>

<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
</head>

<body>
<section class="section">
<div class="container">
<h1 class="title has-text-centered">Basecamp - The Big Picuture</h1>

<%= yield %>
</div>
</section>
</body>
</html>

+ 5
- 0
views/oauth.erb View File

@@ -0,0 +1,5 @@
<h3 class="has-text-centered">Authentication Needed!</h3>

<p class="has-text-centered">
<a class="button is-link" href="<%= authorize_url %>">Authorize With Basecamp</a>
</p>

Loading…
Cancel
Save