github-v3-api 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +9 -5
- data/Gemfile.lock +68 -0
- data/README.rdoc +30 -5
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/get_access_token_sinatra_app.rb.template +25 -0
- data/github-v3-api.gemspec +79 -0
- data/lib/github-v3-api.rb +2 -0
- data/lib/github_v3_api.rb +39 -0
- data/lib/github_v3_api/org.rb +58 -0
- data/lib/github_v3_api/orgs_api.rb +43 -0
- data/spec/github_v3_api_spec.rb +30 -0
- data/spec/org_spec.rb +38 -0
- data/spec/orgs_api_spec.rb +25 -0
- data/spec/spec_helper.rb +1 -1
- metadata +55 -15
data/Gemfile
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
|
-
|
3
|
-
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
2
|
+
gem 'rest-client', '~> 1.6.3'
|
3
|
+
gem 'json', '~> 1.5.3'
|
5
4
|
|
6
|
-
# Add dependencies to develop your gem here.
|
7
|
-
# Include everything needed to run rake, tests, features, etc.
|
8
5
|
group :development do
|
9
6
|
gem "rspec", "~> 2.3.0"
|
10
7
|
gem "bundler", "~> 1.0.0"
|
@@ -13,3 +10,10 @@ group :development do
|
|
13
10
|
gem "reek", "~> 1.2.8"
|
14
11
|
gem "roodi", "~> 2.1.0"
|
15
12
|
end
|
13
|
+
|
14
|
+
# these are for the simple sinatra app that lets you get a GitHub access_token
|
15
|
+
# in order to test this library from IRB.
|
16
|
+
group :sinatra do
|
17
|
+
gem "sinatra"
|
18
|
+
gem "omniauth"
|
19
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,18 +1,74 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
addressable (2.2.4)
|
4
5
|
diff-lcs (1.1.2)
|
6
|
+
faraday (0.6.1)
|
7
|
+
addressable (~> 2.2.4)
|
8
|
+
multipart-post (~> 1.1.0)
|
9
|
+
rack (>= 1.1.0, < 2)
|
5
10
|
git (1.2.5)
|
6
11
|
jeweler (1.6.2)
|
7
12
|
bundler (~> 1.0)
|
8
13
|
git (>= 1.2.5)
|
9
14
|
rake
|
15
|
+
json (1.5.3)
|
16
|
+
mime-types (1.16)
|
17
|
+
multi_json (1.0.3)
|
18
|
+
multi_xml (0.2.2)
|
19
|
+
multipart-post (1.1.2)
|
20
|
+
net-ldap (0.2.2)
|
21
|
+
nokogiri (1.4.6)
|
22
|
+
oa-basic (0.2.6)
|
23
|
+
oa-core (= 0.2.6)
|
24
|
+
rest-client (~> 1.6.0)
|
25
|
+
oa-core (0.2.6)
|
26
|
+
oa-enterprise (0.2.6)
|
27
|
+
addressable (= 2.2.4)
|
28
|
+
net-ldap (~> 0.2.2)
|
29
|
+
nokogiri (~> 1.4.2)
|
30
|
+
oa-core (= 0.2.6)
|
31
|
+
pyu-ruby-sasl (~> 0.0.3.1)
|
32
|
+
rubyntlm (~> 0.1.1)
|
33
|
+
oa-more (0.2.6)
|
34
|
+
multi_json (~> 1.0.0)
|
35
|
+
oa-core (= 0.2.6)
|
36
|
+
rest-client (~> 1.6.0)
|
37
|
+
oa-oauth (0.2.6)
|
38
|
+
faraday (~> 0.6.1)
|
39
|
+
multi_json (~> 1.0.0)
|
40
|
+
multi_xml (~> 0.2.2)
|
41
|
+
oa-core (= 0.2.6)
|
42
|
+
oauth (~> 0.4.0)
|
43
|
+
oauth2 (~> 0.4.1)
|
44
|
+
oa-openid (0.2.6)
|
45
|
+
oa-core (= 0.2.6)
|
46
|
+
rack-openid (~> 1.3.1)
|
47
|
+
ruby-openid-apps-discovery (~> 1.2.0)
|
48
|
+
oauth (0.4.4)
|
49
|
+
oauth2 (0.4.1)
|
50
|
+
faraday (~> 0.6.1)
|
51
|
+
multi_json (>= 0.0.5)
|
52
|
+
omniauth (0.2.6)
|
53
|
+
oa-basic (= 0.2.6)
|
54
|
+
oa-core (= 0.2.6)
|
55
|
+
oa-enterprise (= 0.2.6)
|
56
|
+
oa-more (= 0.2.6)
|
57
|
+
oa-oauth (= 0.2.6)
|
58
|
+
oa-openid (= 0.2.6)
|
59
|
+
pyu-ruby-sasl (0.0.3.3)
|
60
|
+
rack (1.3.0)
|
61
|
+
rack-openid (1.3.1)
|
62
|
+
rack (>= 1.1.0)
|
63
|
+
ruby-openid (>= 2.1.8)
|
10
64
|
rake (0.9.2)
|
11
65
|
rcov (0.9.9)
|
12
66
|
reek (1.2.8)
|
13
67
|
ruby2ruby (~> 1.2)
|
14
68
|
ruby_parser (~> 2.0)
|
15
69
|
sexp_processor (~> 3.0)
|
70
|
+
rest-client (1.6.3)
|
71
|
+
mime-types (>= 1.16)
|
16
72
|
roodi (2.1.0)
|
17
73
|
ruby_parser
|
18
74
|
rspec (2.3.0)
|
@@ -23,12 +79,20 @@ GEM
|
|
23
79
|
rspec-expectations (2.3.0)
|
24
80
|
diff-lcs (~> 1.1.2)
|
25
81
|
rspec-mocks (2.3.0)
|
82
|
+
ruby-openid (2.1.8)
|
83
|
+
ruby-openid-apps-discovery (1.2.0)
|
84
|
+
ruby-openid (>= 2.1.7)
|
26
85
|
ruby2ruby (1.2.5)
|
27
86
|
ruby_parser (~> 2.0)
|
28
87
|
sexp_processor (~> 3.0)
|
29
88
|
ruby_parser (2.0.6)
|
30
89
|
sexp_processor (~> 3.0)
|
90
|
+
rubyntlm (0.1.1)
|
31
91
|
sexp_processor (3.0.5)
|
92
|
+
sinatra (1.2.6)
|
93
|
+
rack (~> 1.1)
|
94
|
+
tilt (>= 1.2.2, < 2.0)
|
95
|
+
tilt (1.3.2)
|
32
96
|
|
33
97
|
PLATFORMS
|
34
98
|
ruby
|
@@ -36,7 +100,11 @@ PLATFORMS
|
|
36
100
|
DEPENDENCIES
|
37
101
|
bundler (~> 1.0.0)
|
38
102
|
jeweler (~> 1.6.0)
|
103
|
+
json (~> 1.5.3)
|
104
|
+
omniauth
|
39
105
|
rcov
|
40
106
|
reek (~> 1.2.8)
|
107
|
+
rest-client (~> 1.6.3)
|
41
108
|
roodi (~> 2.1.0)
|
42
109
|
rspec (~> 2.3.0)
|
110
|
+
sinatra
|
data/README.rdoc
CHANGED
@@ -1,16 +1,41 @@
|
|
1
1
|
= github-v3-api
|
2
2
|
|
3
|
-
|
3
|
+
This library provides Ruby object access to the GitHub v3 API. It's designed to
|
4
|
+
play friendly with web apps that use OAuth2 via GitHub and need to access github
|
5
|
+
repositories without needing to configure or store a specific user's GitHub
|
6
|
+
credentials in the application itself.
|
7
|
+
|
8
|
+
== CLI Testing
|
9
|
+
|
10
|
+
Because this library requires an OAuth2 access token from GitHub, you will need
|
11
|
+
to obtain such a token in order to do command-line testing of the library via
|
12
|
+
IRB. To that end, a template sinatra application is included in the source at
|
13
|
+
<tt>get_access_token_sinatra_app.rb.template</tt>. You will need to copy that
|
14
|
+
file to <tt>get_access_token_sinatra_app.rb</tt> (drop the .template) and
|
15
|
+
replace YOUR_APP_ID and YOUR_APP_SECRET with the values for a GitHub application
|
16
|
+
that you can create at https://github.com/account/applications/new (for the URL
|
17
|
+
and Callback URL options, enter http://localhost:4567 and
|
18
|
+
http://localhost:4567/auth/github/callback respectively.)
|
19
|
+
|
20
|
+
Then just run <tt>ruby get_access_token_sinatra_app.rb</tt> and point your web
|
21
|
+
browser at http://localhost:4567 whereupon you will be prompted to authorize
|
22
|
+
your app at GitHub. If you allow it, you will be presented with an access token
|
23
|
+
that you can then copy and paste in where needed.
|
4
24
|
|
5
25
|
== Contributing to github-v3-api
|
6
26
|
|
7
|
-
* Check out the latest master to make sure the feature hasn't been implemented
|
8
|
-
|
27
|
+
* Check out the latest master to make sure the feature hasn't been implemented
|
28
|
+
or the bug hasn't been fixed yet
|
29
|
+
* Check out the issue tracker to make sure someone already hasn't requested it
|
30
|
+
and/or contributed it
|
9
31
|
* Fork the project
|
10
32
|
* Start a feature/bugfix branch
|
11
33
|
* Commit and push until you are happy with your contribution
|
12
|
-
* Make sure to add tests for it. This is important so I don't break it in a
|
13
|
-
|
34
|
+
* Make sure to add tests for it. This is important so I don't break it in a
|
35
|
+
future version unintentionally.
|
36
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to
|
37
|
+
have your own version, or is otherwise necessary, that is fine, but please
|
38
|
+
isolate to its own commit so I can cherry-pick around it.
|
14
39
|
|
15
40
|
== Copyright
|
16
41
|
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
Bundler.setup(:sinatra)
|
4
|
+
require 'sinatra'
|
5
|
+
require 'openssl'
|
6
|
+
require 'omniauth'
|
7
|
+
|
8
|
+
# Because fuck you, Apple
|
9
|
+
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
10
|
+
|
11
|
+
enable :sessions
|
12
|
+
|
13
|
+
use OmniAuth::Builder do
|
14
|
+
provider :github, YOUR_APP_ID, YOUR_APP_SECRET,
|
15
|
+
:scope => 'user,repo,gist'
|
16
|
+
end
|
17
|
+
|
18
|
+
get '/' do
|
19
|
+
redirect '/auth/github'
|
20
|
+
end
|
21
|
+
|
22
|
+
get '/auth/github/callback' do
|
23
|
+
token = request.env['omniauth.auth']['credentials']['token']
|
24
|
+
"Your GitHub Access Token is #{token}"
|
25
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{github-v3-api}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["John Wilger"]
|
12
|
+
s.date = %q{2011-06-23}
|
13
|
+
s.description = %q{Ponies}
|
14
|
+
s.email = %q{johnwilger@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
".rvmrc",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"get_access_token_sinatra_app.rb.template",
|
30
|
+
"github-v3-api.gemspec",
|
31
|
+
"lib/github-v3-api.rb",
|
32
|
+
"lib/github_v3_api.rb",
|
33
|
+
"lib/github_v3_api/org.rb",
|
34
|
+
"lib/github_v3_api/orgs_api.rb",
|
35
|
+
"spec/github_v3_api_spec.rb",
|
36
|
+
"spec/org_spec.rb",
|
37
|
+
"spec/orgs_api_spec.rb",
|
38
|
+
"spec/spec_helper.rb"
|
39
|
+
]
|
40
|
+
s.homepage = %q{http://github.com/jwilger/github-v3-api}
|
41
|
+
s.licenses = ["MIT"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubygems_version = %q{1.6.2}
|
44
|
+
s.summary = %q{Ruby Client for the GitHub v3 API}
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<rest-client>, ["~> 1.6.3"])
|
51
|
+
s.add_runtime_dependency(%q<json>, ["~> 1.5.3"])
|
52
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
53
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
|
55
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<reek>, ["~> 1.2.8"])
|
57
|
+
s.add_development_dependency(%q<roodi>, ["~> 2.1.0"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<rest-client>, ["~> 1.6.3"])
|
60
|
+
s.add_dependency(%q<json>, ["~> 1.5.3"])
|
61
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
62
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
63
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
64
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
65
|
+
s.add_dependency(%q<reek>, ["~> 1.2.8"])
|
66
|
+
s.add_dependency(%q<roodi>, ["~> 2.1.0"])
|
67
|
+
end
|
68
|
+
else
|
69
|
+
s.add_dependency(%q<rest-client>, ["~> 1.6.3"])
|
70
|
+
s.add_dependency(%q<json>, ["~> 1.5.3"])
|
71
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
72
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
73
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
74
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
75
|
+
s.add_dependency(%q<reek>, ["~> 1.2.8"])
|
76
|
+
s.add_dependency(%q<roodi>, ["~> 2.1.0"])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
data/lib/github-v3-api.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
require 'github_v3_api/orgs_api'
|
4
|
+
require 'github_v3_api/org'
|
5
|
+
|
6
|
+
# This is the main entry-point to the GitHub v3 API.
|
7
|
+
#
|
8
|
+
# example:
|
9
|
+
#
|
10
|
+
# api = GitHubV3API.new('users_github_oath2_access_token')
|
11
|
+
#
|
12
|
+
# # access the GitHub Orgs API
|
13
|
+
# api.orgs
|
14
|
+
# #=> an instance of GitHubV3API::OrgsAPI
|
15
|
+
#
|
16
|
+
class GitHubV3API
|
17
|
+
# Returns a GitHubV3API instance that is able to access github with the
|
18
|
+
# +access_token+ owner's authorization.
|
19
|
+
#
|
20
|
+
# +access_token+:: an OAuth2 access token from GitHub
|
21
|
+
def initialize(access_token)
|
22
|
+
@access_token = access_token
|
23
|
+
end
|
24
|
+
|
25
|
+
# Entry-point for access to the GitHub Orgs API
|
26
|
+
#
|
27
|
+
# Returns an instance of GitHubV3API::OrgsAPI that will use the access_token
|
28
|
+
# associated with this instance.
|
29
|
+
def orgs
|
30
|
+
OrgsAPI.new(self)
|
31
|
+
end
|
32
|
+
|
33
|
+
def get(path) #:nodoc:
|
34
|
+
result = RestClient.get("https://api.github.com" + path,
|
35
|
+
{:accept => :json,
|
36
|
+
:authorization => "token #{@access_token}"})
|
37
|
+
JSON.parse(result)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# See GitHubV3API documentation in lib/github_v3_api.rb
|
2
|
+
class GitHubV3API
|
3
|
+
# Represents a single GitHub Org and provides access to its data attributes.
|
4
|
+
class Org
|
5
|
+
def self.new_with_all_data(api, org_data) #:nodoc:
|
6
|
+
org = self.allocate
|
7
|
+
org.initialize_fetched(api, org_data)
|
8
|
+
org
|
9
|
+
end
|
10
|
+
|
11
|
+
# +api+:: an instance of GitHubV3API::OrgsAPI
|
12
|
+
# +org_data+:: a Hash with keys corresponding to the org data supported by
|
13
|
+
# GitHub
|
14
|
+
#
|
15
|
+
def initialize(api, org_data)
|
16
|
+
@api = api
|
17
|
+
@org_data = org_data
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize_fetched(api, org_data) #:nodoc:
|
21
|
+
initialize(api, org_data)
|
22
|
+
@fetched = true
|
23
|
+
end
|
24
|
+
|
25
|
+
def [](key) #:nodoc:
|
26
|
+
fetch_data unless @fetched
|
27
|
+
@org_data[key]
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.attr_reader(*fields) #:nodoc:
|
31
|
+
fields.each do |field|
|
32
|
+
define_method field do
|
33
|
+
self[field.to_s]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
attr_reader :avatar_url, :billing_email, :blog, :collaborators,
|
39
|
+
:company, :created_at, :disk_usage, :email, :followers, :following,
|
40
|
+
:html_url, :id, :location, :login, :name, :owned_private_repos, :plan,
|
41
|
+
:private_gists, :private_repos, :public_gists, :public_repos, :space,
|
42
|
+
:total_private_repos, :type, :url
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
def org_data #:nodoc:
|
47
|
+
@org_data
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def fetch_data #:nodoc:
|
53
|
+
result = @api.get(@org_data['login'])
|
54
|
+
@org_data = result.org_data
|
55
|
+
@fetched = true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# See GitHubV3API documentation in lib/github_v3_api.rb
|
2
|
+
class GitHubV3API
|
3
|
+
# Provides access to the GitHub Orgs API (http://developer.github.com/v3/orgs/)
|
4
|
+
#
|
5
|
+
# example:
|
6
|
+
#
|
7
|
+
# api = GitHubV3API.new(ACCESS_TOKEN)
|
8
|
+
#
|
9
|
+
# # get list of all orgs to which the user belongs
|
10
|
+
# orgs = api.orgs.list
|
11
|
+
# #=> returns an array of GitHubV3API::Org instances
|
12
|
+
#
|
13
|
+
# an_org = api.orgs.get('github')
|
14
|
+
# #=> returns an instance of GitHubV3API::Org
|
15
|
+
#
|
16
|
+
# an_org.name
|
17
|
+
# #=> 'GitHub'
|
18
|
+
#
|
19
|
+
class OrgsAPI
|
20
|
+
# Typically not used directly. Use GitHubV3API#orgs instead.
|
21
|
+
#
|
22
|
+
# +connection+:: an instance of GitHubV3API
|
23
|
+
def initialize(connection)
|
24
|
+
@connection = connection
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns an array of GitHubV3API::Org instances representing the
|
28
|
+
# public and private orgs to which the current user belongs.
|
29
|
+
def list
|
30
|
+
@connection.get('/user/orgs').map do |org_data|
|
31
|
+
GitHubV3API::Org.new(self, org_data)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns a GitHubV3API::Org instance for the specified +org_login+.
|
36
|
+
#
|
37
|
+
# +org_login+:: the string ID of the organization, e.g. "github"
|
38
|
+
def get(org_login)
|
39
|
+
org_data = @connection.get("/orgs/#{org_login}")
|
40
|
+
GitHubV3API::Org.new_with_all_data(self, org_data)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GitHubV3API do
|
4
|
+
it 'is initialized with an OAuth2 access token' do
|
5
|
+
lambda { GitHubV3API.new('abcde') }.should_not raise_error
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#orgs' do
|
9
|
+
it 'returns an instance of GitHubV3API::OrgsAPI' do
|
10
|
+
api = GitHubV3API.new('abcde')
|
11
|
+
api.orgs.should be_kind_of GitHubV3API::OrgsAPI
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#get' do
|
16
|
+
it 'does a get request to the specified path at the GitHub API server and adds the access token' do
|
17
|
+
RestClient.should_receive(:get) \
|
18
|
+
.with('https://api.github.com/some/path', {:accept => :json, :authorization => 'token abcde'}) \
|
19
|
+
.and_return('{}')
|
20
|
+
api = GitHubV3API.new('abcde')
|
21
|
+
api.get('/some/path')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns the result of parsing the result body as JSON' do
|
25
|
+
RestClient.stub!(:get => "[{\"foo\": \"bar\"}]")
|
26
|
+
api = GitHubV3API.new('abcde')
|
27
|
+
api.get('/something').should == [{"foo" => "bar"}]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/org_spec.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GitHubV3API::Org do
|
4
|
+
describe 'attr_readers' do
|
5
|
+
it 'should define attr_readers that pull values from the org data' do
|
6
|
+
fields = %w(avatar_url billing_email blog collaborators
|
7
|
+
company created_at disk_usage email followers following
|
8
|
+
html_url id location login name owned_private_repos plan
|
9
|
+
private_gists private_repos public_gists public_repos space
|
10
|
+
total_private_repos type url)
|
11
|
+
fields.each do |f|
|
12
|
+
org = GitHubV3API::Org.new_with_all_data(stub('api'), {f.to_s => 'foo'})
|
13
|
+
org.methods.should include(f)
|
14
|
+
org.send(f).should == 'foo'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#[]' do
|
20
|
+
it 'returns the org data for the specified key' do
|
21
|
+
api = mock(GitHubV3API::OrgsAPI)
|
22
|
+
api.should_receive(:get).with('github') \
|
23
|
+
.and_return(GitHubV3API::Org.new(api, 'login' => 'github', 'company' => 'GitHub'))
|
24
|
+
org = GitHubV3API::Org.new(api, 'login' => 'github')
|
25
|
+
org['company'].should == 'GitHub'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'only fetches the data once' do
|
29
|
+
api = mock(GitHubV3API::OrgsAPI)
|
30
|
+
api.should_receive(:get).once.with('github') \
|
31
|
+
.and_return(GitHubV3API::Org.new(api, 'login' => 'github', 'company' => 'GitHub'))
|
32
|
+
org = GitHubV3API::Org.new(api, 'login' => 'github')
|
33
|
+
org['login'].should == 'github'
|
34
|
+
org['company'].should == 'GitHub'
|
35
|
+
org['foo'].should be_nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GitHubV3API::OrgsAPI do
|
4
|
+
describe '#list' do
|
5
|
+
it 'returns the public and private orgs for the authenticated user' do
|
6
|
+
connection = mock(GitHubV3API)
|
7
|
+
connection.should_receive(:get).with('/user/orgs').and_return([:org_hash1, :org_hash2])
|
8
|
+
api = GitHubV3API::OrgsAPI.new(connection)
|
9
|
+
GitHubV3API::Org.should_receive(:new).with(api, :org_hash1).and_return(:org1)
|
10
|
+
GitHubV3API::Org.should_receive(:new).with(api, :org_hash2).and_return(:org2)
|
11
|
+
orgs = api.list
|
12
|
+
orgs.should == [:org1, :org2]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#get' do
|
17
|
+
it 'returns a fully-hydrated Org object for the specified org login' do
|
18
|
+
connection = mock(GitHubV3API)
|
19
|
+
connection.should_receive(:get).with('/orgs/octocat').and_return(:org_hash)
|
20
|
+
api = GitHubV3API::OrgsAPI.new(connection)
|
21
|
+
GitHubV3API::Org.should_receive(:new_with_all_data).with(api, :org_hash).and_return(:org)
|
22
|
+
api.get('octocat').should == :org
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
3
|
require 'rspec'
|
4
|
-
require '
|
4
|
+
require 'github_v3_api'
|
5
5
|
|
6
6
|
# Requires supporting files with custom matchers and macros, etc,
|
7
7
|
# in ./support/ and its subdirectories.
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-v3-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Wilger
|
@@ -19,8 +19,40 @@ date: 2011-06-23 00:00:00 -07:00
|
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
type: :
|
22
|
+
type: :runtime
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 9
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 6
|
32
|
+
- 3
|
33
|
+
version: 1.6.3
|
34
|
+
name: rest-client
|
35
|
+
version_requirements: *id001
|
36
|
+
prerelease: false
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
type: :runtime
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 5
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 5
|
48
|
+
- 3
|
49
|
+
version: 1.5.3
|
50
|
+
name: json
|
51
|
+
version_requirements: *id002
|
52
|
+
prerelease: false
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
type: :development
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
24
56
|
none: false
|
25
57
|
requirements:
|
26
58
|
- - ~>
|
@@ -32,11 +64,11 @@ dependencies:
|
|
32
64
|
- 0
|
33
65
|
version: 2.3.0
|
34
66
|
name: rspec
|
35
|
-
version_requirements: *
|
67
|
+
version_requirements: *id003
|
36
68
|
prerelease: false
|
37
69
|
- !ruby/object:Gem::Dependency
|
38
70
|
type: :development
|
39
|
-
requirement: &
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
40
72
|
none: false
|
41
73
|
requirements:
|
42
74
|
- - ~>
|
@@ -48,11 +80,11 @@ dependencies:
|
|
48
80
|
- 0
|
49
81
|
version: 1.0.0
|
50
82
|
name: bundler
|
51
|
-
version_requirements: *
|
83
|
+
version_requirements: *id004
|
52
84
|
prerelease: false
|
53
85
|
- !ruby/object:Gem::Dependency
|
54
86
|
type: :development
|
55
|
-
requirement: &
|
87
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
56
88
|
none: false
|
57
89
|
requirements:
|
58
90
|
- - ~>
|
@@ -64,11 +96,11 @@ dependencies:
|
|
64
96
|
- 0
|
65
97
|
version: 1.6.0
|
66
98
|
name: jeweler
|
67
|
-
version_requirements: *
|
99
|
+
version_requirements: *id005
|
68
100
|
prerelease: false
|
69
101
|
- !ruby/object:Gem::Dependency
|
70
102
|
type: :development
|
71
|
-
requirement: &
|
103
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
72
104
|
none: false
|
73
105
|
requirements:
|
74
106
|
- - ">="
|
@@ -78,11 +110,11 @@ dependencies:
|
|
78
110
|
- 0
|
79
111
|
version: "0"
|
80
112
|
name: rcov
|
81
|
-
version_requirements: *
|
113
|
+
version_requirements: *id006
|
82
114
|
prerelease: false
|
83
115
|
- !ruby/object:Gem::Dependency
|
84
116
|
type: :development
|
85
|
-
requirement: &
|
117
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
86
118
|
none: false
|
87
119
|
requirements:
|
88
120
|
- - ~>
|
@@ -94,11 +126,11 @@ dependencies:
|
|
94
126
|
- 8
|
95
127
|
version: 1.2.8
|
96
128
|
name: reek
|
97
|
-
version_requirements: *
|
129
|
+
version_requirements: *id007
|
98
130
|
prerelease: false
|
99
131
|
- !ruby/object:Gem::Dependency
|
100
132
|
type: :development
|
101
|
-
requirement: &
|
133
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
102
134
|
none: false
|
103
135
|
requirements:
|
104
136
|
- - ~>
|
@@ -110,7 +142,7 @@ dependencies:
|
|
110
142
|
- 0
|
111
143
|
version: 2.1.0
|
112
144
|
name: roodi
|
113
|
-
version_requirements: *
|
145
|
+
version_requirements: *id008
|
114
146
|
prerelease: false
|
115
147
|
description: Ponies
|
116
148
|
email: johnwilger@gmail.com
|
@@ -131,7 +163,15 @@ files:
|
|
131
163
|
- README.rdoc
|
132
164
|
- Rakefile
|
133
165
|
- VERSION
|
166
|
+
- get_access_token_sinatra_app.rb.template
|
167
|
+
- github-v3-api.gemspec
|
134
168
|
- lib/github-v3-api.rb
|
169
|
+
- lib/github_v3_api.rb
|
170
|
+
- lib/github_v3_api/org.rb
|
171
|
+
- lib/github_v3_api/orgs_api.rb
|
172
|
+
- spec/github_v3_api_spec.rb
|
173
|
+
- spec/org_spec.rb
|
174
|
+
- spec/orgs_api_spec.rb
|
135
175
|
- spec/spec_helper.rb
|
136
176
|
has_rdoc: true
|
137
177
|
homepage: http://github.com/jwilger/github-v3-api
|