ghee 0.11.16 → 0.12.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/lib/ghee/api/orgs.rb +16 -12
- data/lib/ghee/api/users.rb +23 -9
- data/lib/ghee/resource_proxy.rb +120 -112
- data/lib/ghee/version.rb +1 -1
- data/spec/ghee/api/orgs_spec.rb +9 -0
- data/spec/ghee/api/users_spec.rb +17 -0
- data/spec/ghee/resource_proxy_spec.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c51e8b1e6c08b70499f35de0a23cae8b63e1a6e
|
4
|
+
data.tar.gz: 049da506b9d66e381fadfe141b50bd1eccafb4ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9ed847d603f4afdfb209baeae64510b42507caaf5d9a663089d3d702e66aec9f80049884e8cc54a050dd1b38df1da5617a6fb672b2ee735490cab6941771e14
|
7
|
+
data.tar.gz: 2e2204ba0e54d1c497e9f66cb03f09ba00e8b2c8c7b0bdb694b3e300ecc9e518b965ff9d754f42386d5addadbf7b46e8e10ac07b6be981c2cb3e3f684934374a
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1.
|
1
|
+
2.1.5
|
data/lib/ghee/api/orgs.rb
CHANGED
@@ -10,6 +10,12 @@ class Ghee
|
|
10
10
|
#
|
11
11
|
module Orgs
|
12
12
|
|
13
|
+
module Memberships
|
14
|
+
class MembershipsProxy < ::Ghee::ResourceProxy
|
15
|
+
accept_header "application/vnd.github.moondragon+json"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
13
19
|
# Orgs::Teams module handles all of the Github Organization Teams
|
14
20
|
# API endpoints
|
15
21
|
#
|
@@ -41,9 +47,9 @@ class Ghee
|
|
41
47
|
class Proxy < ::Ghee::ResourceProxy
|
42
48
|
include Ghee::CUD
|
43
49
|
|
44
|
-
def members(name=nil)
|
50
|
+
def members(name=nil, &block)
|
45
51
|
prefix = name ? "#{path_prefix}/members/#{name}" : "#{path_prefix}/members"
|
46
|
-
Ghee::API::Orgs::Teams::Members::Proxy.new(connection, prefix)
|
52
|
+
Ghee::API::Orgs::Teams::Members::Proxy.new(connection, prefix, name, &block)
|
47
53
|
end
|
48
54
|
|
49
55
|
end
|
@@ -59,20 +65,19 @@ class Ghee
|
|
59
65
|
#
|
60
66
|
# Returns json
|
61
67
|
#
|
62
|
-
def teams(number=nil,
|
63
|
-
params = number if number.is_a?Hash
|
68
|
+
def teams(number=nil, &block)
|
64
69
|
prefix = (!number.is_a?(Hash) and number) ? "./teams/#{number}" : "#{path_prefix}/teams"
|
65
|
-
Ghee::API::Orgs::Teams::Proxy.new(connection, prefix,
|
70
|
+
Ghee::API::Orgs::Teams::Proxy.new(connection, prefix, number, &block)
|
66
71
|
end
|
67
72
|
|
68
73
|
# Repos for a orgs
|
69
74
|
#
|
70
75
|
# Returns json
|
71
76
|
#
|
72
|
-
def repos(name=nil,
|
77
|
+
def repos(name=nil, &block)
|
73
78
|
params = name if name.is_a?Hash
|
74
79
|
prefix = (!name.is_a?(Hash) and name) ? "./repos/#{self["login"]}/#{name}" : "#{path_prefix}/repos"
|
75
|
-
Ghee::API::Repos::Proxy.new(connection,prefix,
|
80
|
+
Ghee::API::Repos::Proxy.new(connection,prefix,name, &block)
|
76
81
|
end
|
77
82
|
|
78
83
|
# User Membership for an org
|
@@ -82,7 +87,7 @@ class Ghee
|
|
82
87
|
|
83
88
|
def memberships(user, &block)
|
84
89
|
prefix = "#{path_prefix}/memberships/#{user}"
|
85
|
-
|
90
|
+
Ghee::API::Orgs::Memberships::MembershipsProxy.new(connection, prefix, nil, &block)
|
86
91
|
end
|
87
92
|
end
|
88
93
|
|
@@ -91,7 +96,7 @@ class Ghee
|
|
91
96
|
# Returns json
|
92
97
|
#
|
93
98
|
def team(number, params={})
|
94
|
-
prefix = "
|
99
|
+
prefix = "./teams/#{number}"
|
95
100
|
Ghee::API::Orgs::Teams::Proxy.new(connection, prefix, params)
|
96
101
|
end
|
97
102
|
|
@@ -102,10 +107,9 @@ class Ghee
|
|
102
107
|
#
|
103
108
|
# Returns json
|
104
109
|
#
|
105
|
-
def orgs(name=nil,
|
106
|
-
params = name if name.is_a?Hash
|
110
|
+
def orgs(name=nil, &block)
|
107
111
|
prefix = (!name.is_a?(Hash) and name) ? "./orgs/#{name}" : "user/orgs"
|
108
|
-
Proxy.new(connection, prefix,
|
112
|
+
Proxy.new(connection, prefix, name, &block)
|
109
113
|
end
|
110
114
|
end
|
111
115
|
end
|
data/lib/ghee/api/users.rb
CHANGED
@@ -5,6 +5,20 @@ class Ghee
|
|
5
5
|
#
|
6
6
|
module API
|
7
7
|
|
8
|
+
module Membership
|
9
|
+
class MembershipProxy < ::Ghee::ResourceProxy
|
10
|
+
def admin?
|
11
|
+
self['role'] == "admin"
|
12
|
+
end
|
13
|
+
def active?
|
14
|
+
self['state'] == 'active'
|
15
|
+
end
|
16
|
+
def activate!
|
17
|
+
connection.patch(path_prefix, {state: "active"}).body
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
8
22
|
# The Users module handles all of the Github User
|
9
23
|
# API endpoints
|
10
24
|
#
|
@@ -19,17 +33,17 @@ class Ghee
|
|
19
33
|
# enables defining methods on the proxy object
|
20
34
|
#
|
21
35
|
class Proxy < ::Ghee::ResourceProxy
|
22
|
-
|
23
36
|
#Org membership for the user
|
24
37
|
#
|
25
38
|
#State: string to limit scope to either active or
|
26
39
|
#pending
|
27
40
|
#
|
28
41
|
#Returns json
|
29
|
-
def
|
30
|
-
|
31
|
-
|
42
|
+
def org(name, &block)
|
43
|
+
prefix = "#{path_prefix}/#{name}"
|
44
|
+
Ghee::API::Membership::MembershipProxy.new(connection, prefix, nil, &block)
|
32
45
|
end
|
46
|
+
|
33
47
|
end
|
34
48
|
end
|
35
49
|
|
@@ -71,9 +85,9 @@ class Ghee
|
|
71
85
|
end
|
72
86
|
|
73
87
|
# Returns a Memberships Proxy
|
74
|
-
def memberships
|
75
|
-
prefix = "#{path_prefix}/memberships"
|
76
|
-
Ghee::API::Users::Memberships::Proxy.new(connection, prefix)
|
88
|
+
def memberships(params={state: "active"}, &block)
|
89
|
+
prefix = "#{path_prefix}/memberships/orgs"
|
90
|
+
Ghee::API::Users::Memberships::Proxy.new(connection, prefix, params, &block)
|
77
91
|
end
|
78
92
|
end
|
79
93
|
|
@@ -81,8 +95,8 @@ class Ghee
|
|
81
95
|
#
|
82
96
|
# Returns json
|
83
97
|
#
|
84
|
-
def user
|
85
|
-
Proxy.new(connection, './user')
|
98
|
+
def user(&block)
|
99
|
+
Proxy.new(connection, './user', nil, &block)
|
86
100
|
end
|
87
101
|
|
88
102
|
# Get a single user
|
data/lib/ghee/resource_proxy.rb
CHANGED
@@ -8,7 +8,7 @@ class Ghee
|
|
8
8
|
class ResourceProxy
|
9
9
|
|
10
10
|
# Undefine methods that might get in the way
|
11
|
-
instance_methods.each { |m| undef_method m unless m =~ /^__|instance_eval|instance_variable_get|object_id|respond_to/ }
|
11
|
+
instance_methods.each { |m| undef_method m unless m =~ /^__|instance_eval|instance_variable_get|object_id|respond_to|class/ }
|
12
12
|
|
13
13
|
include Ghee::CUD
|
14
14
|
|
@@ -18,139 +18,147 @@ class Ghee
|
|
18
18
|
# Expose pagination data
|
19
19
|
attr_reader :current_page, :total, :pagination
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
# path_prefix - String
|
26
|
-
#
|
27
|
-
def initialize(connection, path_prefix, params = {}, &block)
|
28
|
-
params = {} if !params.is_a?Hash
|
29
|
-
@connection, @path_prefix, @params = connection, URI.escape(path_prefix), params
|
30
|
-
@block = block if block
|
31
|
-
subject if block
|
21
|
+
def self.accept_header(header)
|
22
|
+
define_method "accept_type" do
|
23
|
+
return @_accept_type ||= "#{header}"
|
24
|
+
end
|
32
25
|
end
|
33
26
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
27
|
+
# Instantiates proxy with the connection
|
28
|
+
# and path_prefix
|
29
|
+
#
|
30
|
+
# connection - Ghee::Connection object
|
31
|
+
# path_prefix - String
|
32
|
+
#
|
33
|
+
def initialize(connection, path_prefix, params = {}, &block)
|
34
|
+
params = {} if !params.is_a?Hash
|
35
|
+
@connection, @path_prefix, @params = connection, URI.escape(path_prefix), params
|
36
|
+
@block = block if block
|
37
|
+
subject if block
|
38
|
+
end
|
44
39
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
40
|
+
# Method_missing takes any message passed
|
41
|
+
# to the ResourceProxy and sends it to the
|
42
|
+
# real object
|
43
|
+
#
|
44
|
+
# message - Message object
|
45
|
+
# args* - Arguements passed
|
46
|
+
#
|
47
|
+
def method_missing(message, *args, &block)
|
48
|
+
subject.send(message, *args, &block)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Raw is the raw response from the faraday
|
52
|
+
# Use this if you need access to status codes
|
53
|
+
# or header values
|
54
|
+
#
|
55
|
+
def raw
|
56
|
+
connection.get(path_prefix){|req| req.params.merge!params }
|
57
|
+
end
|
58
|
+
|
59
|
+
# Subject is the response body parsed
|
60
|
+
# as json
|
61
|
+
#
|
62
|
+
# Returns json
|
63
|
+
#
|
64
|
+
def subject
|
65
|
+
@subject ||= connection.get(path_prefix) do |req|
|
66
|
+
req.params.merge!params
|
67
|
+
req.headers["Accept"] = accept_type if self.respond_to? :accept_type
|
68
|
+
@block.call(req)if @block
|
69
|
+
end.body
|
70
|
+
end
|
71
|
+
|
72
|
+
# Paginate is a helper method to handle
|
73
|
+
# request pagination to the github api
|
74
|
+
#
|
75
|
+
# options - Hash containing pagination params
|
76
|
+
# eg;
|
77
|
+
# :per_page => 100, :page => 1
|
78
|
+
#
|
79
|
+
# Returns self
|
80
|
+
#
|
81
|
+
def paginate(options)
|
82
|
+
@current_page = options.fetch(:page) {raise ArgumentError, ":page parameter required"}
|
83
|
+
per_page = options.delete(:per_page) || 30
|
84
|
+
response = connection.get do |req|
|
85
|
+
req.url path_prefix, :per_page => per_page, :page => current_page
|
86
|
+
req.params.merge! params
|
51
87
|
end
|
52
88
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
#
|
58
|
-
def subject
|
59
|
-
@subject ||= connection.get(path_prefix) do |req|
|
60
|
-
req.params.merge!params
|
61
|
-
@block.call(req)if @block
|
62
|
-
end.body
|
89
|
+
if @subject.nil?
|
90
|
+
@subject = response.body
|
91
|
+
else
|
92
|
+
@subject = @subject.concat response.body
|
63
93
|
end
|
64
94
|
|
65
|
-
|
66
|
-
# request pagination to the github api
|
67
|
-
#
|
68
|
-
# options - Hash containing pagination params
|
69
|
-
# eg;
|
70
|
-
# :per_page => 100, :page => 1
|
71
|
-
#
|
72
|
-
# Returns self
|
73
|
-
#
|
74
|
-
def paginate(options)
|
75
|
-
@current_page = options.fetch(:page) {raise ArgumentError, ":page parameter required"}
|
76
|
-
per_page = options.delete(:per_page) || 30
|
77
|
-
response = connection.get do |req|
|
78
|
-
req.url path_prefix, :per_page => per_page, :page => current_page
|
79
|
-
req.params.merge! params
|
80
|
-
end
|
95
|
+
parse_link_header response.headers.delete("link")
|
81
96
|
|
82
|
-
|
83
|
-
|
84
|
-
else
|
85
|
-
@subject = @subject.concat response.body
|
86
|
-
end
|
87
|
-
|
88
|
-
parse_link_header response.headers.delete("link")
|
97
|
+
return self
|
98
|
+
end
|
89
99
|
|
90
|
-
|
91
|
-
|
100
|
+
def all
|
101
|
+
return self if pagination && next_page.nil?
|
92
102
|
|
93
|
-
|
94
|
-
return self if pagination && next_page.nil?
|
103
|
+
self.paginate :per_page => 100, :page => next_page || 1
|
95
104
|
|
96
|
-
|
105
|
+
self.all
|
106
|
+
end
|
97
107
|
|
98
|
-
|
108
|
+
def all_parallel
|
109
|
+
connection = @connection.parallel_connection
|
110
|
+
headers = connection.head(path_prefix) do |req|
|
111
|
+
req.params.merge! params.merge(:per_page => 100)
|
99
112
|
end
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
pages = pagination_data headers.headers.delete("link")
|
107
|
-
requests = []
|
108
|
-
connection.in_parallel do
|
109
|
-
pages[:pages].to_i.times do |i|
|
110
|
-
requests << connection.get(path_prefix) do |req|
|
111
|
-
req.params.merge! params.merge(:per_page => 100, :page => i + 1)
|
112
|
-
end
|
113
|
+
pages = pagination_data headers.headers.delete("link")
|
114
|
+
requests = []
|
115
|
+
connection.in_parallel do
|
116
|
+
pages[:pages].to_i.times do |i|
|
117
|
+
requests << connection.get(path_prefix) do |req|
|
118
|
+
req.params.merge! params.merge(:per_page => 100, :page => i + 1)
|
113
119
|
end
|
114
120
|
end
|
115
|
-
requests.inject([]) do |results, page|
|
116
|
-
results.concat(page.body)
|
117
|
-
end
|
118
121
|
end
|
122
|
+
requests.inject([]) do |results, page|
|
123
|
+
results.concat(page.body)
|
124
|
+
end
|
125
|
+
end
|
119
126
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end
|
127
|
+
# Generate first_page, last_page, next_page, prev_page convienence methods
|
128
|
+
%w{ next prev first last }.each do |term|
|
129
|
+
define_method "#{term}_page" do
|
130
|
+
pagination ? pagination[term.to_sym] ? pagination[term.to_sym][:page] : nil : nil
|
125
131
|
end
|
132
|
+
end
|
126
133
|
|
127
|
-
|
134
|
+
def build_prefix(first_argument, endpoint)
|
135
|
+
(!first_argument.is_a?(Hash) && !first_argument.nil?) ?
|
136
|
+
File.join(path_prefix, "/#{endpoint}/#{first_argument}") : File.join(path_prefix, "/#{endpoint}")
|
137
|
+
end
|
128
138
|
|
129
|
-
|
130
|
-
parse_link_header header
|
131
|
-
{ pages: @pagination[:last][:page] }
|
132
|
-
end
|
139
|
+
private
|
133
140
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
141
|
+
def pagination_data(header)
|
142
|
+
parse_link_header header
|
143
|
+
{ pages: @pagination[:last][:page] }
|
144
|
+
end
|
138
145
|
|
139
|
-
def parse_link_header(header)
|
140
|
-
return @total = subject.size, @pagination = {} if header.nil?
|
141
|
-
require 'cgi'
|
142
|
-
pattern = /<(.*)>;\s+rel="(.*)"/
|
143
|
-
matches = {}
|
144
|
-
header.split(',').each do |m|
|
145
|
-
match = pattern.match m
|
146
|
-
uri = URI.parse(match[1])
|
147
|
-
uri_params = CGI.parse(uri.query)
|
148
|
-
page = uri_params["page"].first.to_i
|
149
|
-
per_page = uri_params["per_page"] ? uri_params["per_page"].first.to_i : 30
|
150
|
-
matches[match[2].to_sym] = {:link => match[1], :page => page, :per_page => per_page}
|
151
|
-
end
|
152
|
-
@pagination = matches
|
153
|
-
end
|
154
146
|
|
147
|
+
def parse_link_header(header)
|
148
|
+
return @total = subject.size, @pagination = {} if header.nil?
|
149
|
+
require 'cgi'
|
150
|
+
pattern = /<(.*)>;\s+rel="(.*)"/
|
151
|
+
matches = {}
|
152
|
+
header.split(',').each do |m|
|
153
|
+
match = pattern.match m
|
154
|
+
uri = URI.parse(match[1])
|
155
|
+
uri_params = CGI.parse(uri.query)
|
156
|
+
page = uri_params["page"].first.to_i
|
157
|
+
per_page = uri_params["per_page"] ? uri_params["per_page"].first.to_i : 30
|
158
|
+
matches[match[2].to_sym] = {:link => match[1], :page => page, :per_page => per_page}
|
159
|
+
end
|
160
|
+
@pagination = matches
|
155
161
|
end
|
162
|
+
|
163
|
+
end
|
156
164
|
end
|
data/lib/ghee/version.rb
CHANGED
data/spec/ghee/api/orgs_spec.rb
CHANGED
@@ -29,6 +29,15 @@ describe Ghee::API::Orgs do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
describe "#memberships" do
|
33
|
+
it "should return a membership" do
|
34
|
+
VCR.use_cassette "orgs(login).memberships(user)" do
|
35
|
+
membership = subject.orgs(GH_ORG).memberships(GH_USER)
|
36
|
+
membership["state"].should == "active"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
32
41
|
describe "#repos" do
|
33
42
|
it "should return a list of repos" do
|
34
43
|
VCR.use_cassette "orgs(login).repos" do
|
data/spec/ghee/api/users_spec.rb
CHANGED
@@ -3,6 +3,23 @@ require 'spec_helper'
|
|
3
3
|
describe Ghee::API::Users do
|
4
4
|
subject { Ghee.new(GH_AUTH) }
|
5
5
|
|
6
|
+
describe "#memberships" do
|
7
|
+
it "should return a list of memberships" do
|
8
|
+
VCR.use_cassette('user.memberships') do
|
9
|
+
memberships = subject.user.memberships
|
10
|
+
memberships.size.should > 0
|
11
|
+
end
|
12
|
+
end
|
13
|
+
it "should return a single membership" do
|
14
|
+
VCR.use_cassette('user.memberships.org(org)') do
|
15
|
+
memberships = subject.user.memberships.org(GH_ORG)
|
16
|
+
memberships['state'].should == 'active'
|
17
|
+
memberships.active?.should be_true
|
18
|
+
memberships.admin?.should be_true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
6
23
|
describe "#user" do
|
7
24
|
it "should return authenticated user" do
|
8
25
|
VCR.use_cassette('user') do
|
@@ -199,6 +199,15 @@ describe Ghee::ResourceProxy do
|
|
199
199
|
end
|
200
200
|
end
|
201
201
|
|
202
|
+
describe "#build_prefix" do
|
203
|
+
it 'should not append the prefix if hash' do
|
204
|
+
subject.build_prefix({}, "bar").should == "/foo/bar"
|
205
|
+
end
|
206
|
+
it 'should append the prefix if param is not a hash' do
|
207
|
+
subject.build_prefix("baz", "bar").should == "/foo/bar/baz"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
202
211
|
describe "#method_missing" do
|
203
212
|
it "should pass message and args to target" do
|
204
213
|
subject.upcase.should == "BAR!"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Rauh
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-03-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|