ghee 0.9.12 → 0.10.13
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 -0
- data/Gemfile +4 -0
- data/ghee.gemspec +3 -1
- data/lib/ghee.rb +12 -1
- data/lib/ghee/api/collaborators.rb +4 -5
- data/lib/ghee/api/commits.rb +8 -9
- data/lib/ghee/api/contents.rb +47 -0
- data/lib/ghee/api/downloads.rb +42 -44
- data/lib/ghee/api/issues.rb +1 -0
- data/lib/ghee/api/repos.rb +1 -1
- data/lib/ghee/api/users.rb +1 -1
- data/lib/ghee/connection.rb +8 -5
- data/lib/ghee/errors.rb +95 -0
- data/lib/ghee/resource_proxy.rb +36 -2
- data/lib/ghee/version.rb +1 -1
- data/spec/ghee/api/contents_spec.rb +41 -0
- data/spec/ghee/api/{downloads_spec.rb → downloads_spec.rb.ignore} +1 -1
- data/spec/ghee/api/events_spec.rb +2 -2
- data/spec/ghee/api/gists_spec.rb +3 -3
- data/spec/ghee/api/issues_spec.rb +2 -2
- data/spec/ghee/api/repos_spec.rb +1 -1
- data/spec/ghee/api/search_spec.rb +2 -2
- data/spec/ghee/api/users_spec.rb +6 -6
- data/spec/ghee/concurrency_spec.rb +43 -0
- data/spec/spec_helper.rb +1 -0
- metadata +57 -44
- data/spec/fyeah.jpg +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ec649170d62b1aa4eca48afcccccc946bd35c2b
|
4
|
+
data.tar.gz: e44cbef003a21da310360ad264e1fa77899e544c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bb442c4b736e1ff21145ead4be9bfcb5244fc132a93257f997f577dc8da28481f7be14ea984a85959992f891897af47de43fb2b8645277ee288216c18423082
|
7
|
+
data.tar.gz: 046d3b69594ecf6ac30bc8e3fc9c157539a91bb956c00fcb488052d06f700c0d2de96965f575fa39fde496d8a0ea9a5875d0212f31f06cedc17ac208f967df62
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.2
|
data/Gemfile
CHANGED
data/ghee.gemspec
CHANGED
@@ -18,11 +18,13 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_dependency 'faraday', '
|
21
|
+
s.add_dependency 'faraday', '~> 0.9'
|
22
22
|
s.add_dependency 'faraday_middleware', '~> 0.9'
|
23
23
|
s.add_dependency 'hashie', '~> 3.3.2'
|
24
24
|
s.add_dependency 'multi_json', '~> 1.3'
|
25
25
|
s.add_dependency 'highline', '~> 1.6.15'
|
26
|
+
s.add_dependency 'typhoeus', '~> 0.7.0'
|
27
|
+
|
26
28
|
s.add_development_dependency 'rake'
|
27
29
|
s.add_development_dependency 'json_pure'
|
28
30
|
s.add_development_dependency 'rspec', '~>2.9.0'
|
data/lib/ghee.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'ghee/version'
|
3
3
|
require 'ghee/connection'
|
4
|
+
require 'ghee/errors'
|
4
5
|
require 'ghee/uri_escape'
|
5
6
|
require 'ghee/state_methods'
|
6
7
|
require 'ghee/resource_proxy'
|
@@ -13,7 +14,6 @@ require 'ghee/api/issues'
|
|
13
14
|
require 'ghee/api/milestones'
|
14
15
|
require 'ghee/api/orgs'
|
15
16
|
require 'ghee/api/git_data'
|
16
|
-
require 'ghee/api/downloads'
|
17
17
|
require 'ghee/api/labels'
|
18
18
|
require 'ghee/api/hooks'
|
19
19
|
require 'ghee/api/collaborators'
|
@@ -25,6 +25,7 @@ require 'ghee/api/emails'
|
|
25
25
|
require 'ghee/api/followers'
|
26
26
|
require 'ghee/api/pulls'
|
27
27
|
require 'ghee/api/search'
|
28
|
+
require 'ghee/api/contents'
|
28
29
|
|
29
30
|
class Ghee
|
30
31
|
attr_reader :connection
|
@@ -42,9 +43,19 @@ class Ghee
|
|
42
43
|
# Access_token - String of the access_token
|
43
44
|
#
|
44
45
|
def initialize(options = {}, &block)
|
46
|
+
@options = options
|
47
|
+
@block = block if block
|
45
48
|
return @connection = Ghee::Connection.new(options, &block)
|
46
49
|
end
|
47
50
|
|
51
|
+
def in_parallel(adapter = :typhoeus, &block)
|
52
|
+
ghee = self.class.new @options, &@block
|
53
|
+
ghee.connection.adapter adapter
|
54
|
+
ghee.connection.in_parallel do
|
55
|
+
block.call ghee
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
48
59
|
def self.basic_auth(user_name, password, api_url = nil)
|
49
60
|
options = { :basic_auth => {:user_name => user_name, :password => password} }
|
50
61
|
options[:api_url] = api_url if api_url
|
@@ -22,16 +22,15 @@ class Ghee
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
#
|
25
|
+
# Repos::Proxy inherits from Ghee::Proxy and
|
26
26
|
# enables defining methods on the proxy object
|
27
27
|
#
|
28
28
|
class Proxy < ::Ghee::ResourceProxy
|
29
|
-
def collaborators(user=nil)
|
30
|
-
prefix =
|
31
|
-
return user ? connection.get(prefix).status == 204 :
|
29
|
+
def collaborators(user=nil, &block)
|
30
|
+
prefix = build_prefix user, "collaborators"
|
31
|
+
return (!user.is_a?(Hash) and number) ? connection.get(prefix).status == 204 : Collaborators::Proxy.new(connection, prefix, user, &block)
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
data/lib/ghee/api/commits.rb
CHANGED
@@ -14,7 +14,7 @@ class Ghee
|
|
14
14
|
class Proxy < ::Ghee::ResourceProxy
|
15
15
|
|
16
16
|
def comments
|
17
|
-
|
17
|
+
Comments::Proxy.new connection, path_prefix
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -42,21 +42,20 @@ class Ghee
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
#
|
45
|
+
# Repos::Proxy inherits from Ghee::Proxy and
|
46
46
|
# enables defining methods on the proxy object
|
47
47
|
#
|
48
48
|
class Proxy < ::Ghee::ResourceProxy
|
49
49
|
def compare(base, head)
|
50
50
|
connection.get("#{path_prefix}/compare/#{base}...#{head}").body
|
51
51
|
end
|
52
|
-
def commits(sha=nil,
|
53
|
-
|
54
|
-
|
55
|
-
Ghee::API::Repos::Commits::Proxy.new(connection, prefix, params)
|
52
|
+
def commits(sha=nil, &block)
|
53
|
+
prefix = build_prefix sha, "commits"
|
54
|
+
Commits::Proxy.new(connection, prefix, sha, &block)
|
56
55
|
end
|
57
|
-
def comments(id=nil)
|
58
|
-
prefix =
|
59
|
-
|
56
|
+
def comments(id=nil, &block)
|
57
|
+
prefix = build_prefix id, "comments"
|
58
|
+
Comments::Proxy.new connection, prefix, id, &block
|
60
59
|
end
|
61
60
|
end
|
62
61
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class Ghee
|
2
|
+
|
3
|
+
# API module encapsulates all of API endpoints
|
4
|
+
# implemented thus far
|
5
|
+
#
|
6
|
+
module API
|
7
|
+
|
8
|
+
# The Repos module handles all of the Github Repo
|
9
|
+
# API endpoints
|
10
|
+
#
|
11
|
+
module Repos
|
12
|
+
# The Contents module handles all of the Github repos file contents
|
13
|
+
# API endpoints
|
14
|
+
#
|
15
|
+
module Contents
|
16
|
+
class Proxy < ::Ghee::ResourceProxy
|
17
|
+
attr_accessor :path
|
18
|
+
def create(message, content=nil)
|
19
|
+
if content.nil?
|
20
|
+
message.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
21
|
+
attributes = { path: path }.merge message
|
22
|
+
attributes[:content] = Base64.encode64 attributes[:content]
|
23
|
+
else
|
24
|
+
attributes = {
|
25
|
+
path: path,
|
26
|
+
message: message,
|
27
|
+
content: Base64.encode64(content)
|
28
|
+
}
|
29
|
+
end
|
30
|
+
connection.put(path_prefix, attributes).body
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Proxy < ::Ghee::ResourceProxy
|
36
|
+
def contents(path, &block)
|
37
|
+
proxy = Contents::Proxy.new connection, "#{path_prefix}/contents/#{path}", nil, &block
|
38
|
+
proxy.path = path
|
39
|
+
proxy
|
40
|
+
end
|
41
|
+
def readme(&block)
|
42
|
+
Contents::Proxy.new connection, "#{path_prefix}/readme", {}, &block
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/ghee/api/downloads.rb
CHANGED
@@ -1,56 +1,54 @@
|
|
1
1
|
class Ghee
|
2
2
|
module API
|
3
|
-
module
|
4
|
-
|
5
|
-
class Proxy < ::Ghee::ResourceProxy
|
3
|
+
module Downloads
|
4
|
+
class Proxy < ::Ghee::ResourceProxy
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
6
|
+
# Creates
|
7
|
+
#
|
8
|
+
# return json
|
9
|
+
#
|
10
|
+
def create(file_path, description="")
|
11
|
+
params = {
|
12
|
+
:name => File.basename(file_path),
|
13
|
+
:size => File.size(file_path),
|
14
|
+
:description => description
|
15
|
+
}
|
16
|
+
download = connection.post(path_prefix, params).body
|
17
|
+
s3 = Faraday.new(:url => download["s3_url"]) do |builder|
|
18
|
+
builder.request :multipart
|
19
|
+
builder.request :url_encoded
|
21
20
|
|
22
|
-
|
23
|
-
end
|
24
|
-
upload = {
|
25
|
-
:key => download["path"],
|
26
|
-
:acl => download["acl"],
|
27
|
-
:success_action_status => 201,
|
28
|
-
:Filename => download["name"],
|
29
|
-
:AWSAccessKeyId => download["accesskeyid"],
|
30
|
-
:Policy => download["policy"],
|
31
|
-
:Signature => download["signature"],
|
32
|
-
:"Content-Type" => download["mime_type"],
|
33
|
-
:file => Faraday::UploadIO.new(file_path, download["mime_type"])
|
34
|
-
}
|
35
|
-
s3.post("/",upload).status == 201
|
36
|
-
return download
|
21
|
+
builder.adapter :net_http
|
37
22
|
end
|
23
|
+
upload = {
|
24
|
+
:key => download["path"],
|
25
|
+
:acl => download["acl"],
|
26
|
+
:success_action_status => 201,
|
27
|
+
:Filename => download["name"],
|
28
|
+
:AWSAccessKeyId => download["accesskeyid"],
|
29
|
+
:Policy => download["policy"],
|
30
|
+
:Signature => download["signature"],
|
31
|
+
:"Content-Type" => download["mime_type"],
|
32
|
+
:file => Faraday::UploadIO.new(file_path, download["mime_type"])
|
33
|
+
}
|
34
|
+
s3.post("/",upload).status == 201
|
35
|
+
return download
|
36
|
+
end
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
38
|
+
# Destroys
|
39
|
+
#
|
40
|
+
# return boolean
|
41
|
+
#
|
42
|
+
def destroy
|
43
|
+
connection.delete(path_prefix).status == 204
|
46
44
|
end
|
47
45
|
end
|
46
|
+
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
48
|
+
class Proxy < ::Ghee::ResourceProxy
|
49
|
+
def downloads(id=nil)
|
50
|
+
prefix = id ? "#{path_prefix}/downloads/#{id}" :"#{path_prefix}/downloads"
|
51
|
+
Ghee::API::Downloads::Proxy.new(connection, prefix)
|
54
52
|
end
|
55
53
|
end
|
56
54
|
end
|
data/lib/ghee/api/issues.rb
CHANGED
data/lib/ghee/api/repos.rb
CHANGED
data/lib/ghee/api/users.rb
CHANGED
data/lib/ghee/connection.rb
CHANGED
@@ -6,6 +6,12 @@ class Ghee
|
|
6
6
|
class Connection < Faraday::Connection
|
7
7
|
attr_reader :hash
|
8
8
|
|
9
|
+
def parallel_connection(adapter=:typhoeus)
|
10
|
+
conn = self.class.new @hash
|
11
|
+
conn.adapter adapter
|
12
|
+
conn
|
13
|
+
end
|
14
|
+
|
9
15
|
# Instantiates connection, accepts an options hash
|
10
16
|
# for authenticated access
|
11
17
|
#
|
@@ -21,13 +27,10 @@ class Ghee
|
|
21
27
|
|
22
28
|
super(hash[:api_url] || 'https://api.github.com') do |builder|
|
23
29
|
yield builder if block_given?
|
30
|
+
builder.use Faraday::Response::RaiseGheeError
|
24
31
|
builder.use FaradayMiddleware::EncodeJson
|
25
|
-
builder.use FaradayMiddleware::
|
26
|
-
builder.use FaradayMiddleware::ParseJson
|
27
|
-
# builder.use Ghee::Middleware::UriEscape
|
32
|
+
builder.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
|
28
33
|
builder.adapter Faraday.default_adapter
|
29
|
-
|
30
|
-
|
31
34
|
end
|
32
35
|
|
33
36
|
self.headers["Authorization"] = "token #{access_token}" if access_token
|
data/lib/ghee/errors.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'json/ext'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
class Ghee
|
5
|
+
# Custom error class for rescuing from all GitHub errors
|
6
|
+
class Error < StandardError
|
7
|
+
def initialize(response=nil)
|
8
|
+
@response = response
|
9
|
+
super(build_error_message)
|
10
|
+
end
|
11
|
+
|
12
|
+
def response_body
|
13
|
+
@response_body ||= if (body = @response[:body]) && !body.empty?
|
14
|
+
if false and body.is_a?(String)
|
15
|
+
MultiJson.load(body, :symbolize_keys => true)
|
16
|
+
else
|
17
|
+
body
|
18
|
+
end
|
19
|
+
else
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def build_error_message
|
27
|
+
return nil if @response.nil?
|
28
|
+
|
29
|
+
message = if response_body
|
30
|
+
"#{response_body["error"] || response_body["message"] || ''}"
|
31
|
+
else
|
32
|
+
''
|
33
|
+
end
|
34
|
+
|
35
|
+
errors = unless message.empty?
|
36
|
+
response_body["errors"] ? " #{response_body["errors"].to_a.map{|e|e.message || e.code}.join(', ')} " : ''
|
37
|
+
end
|
38
|
+
|
39
|
+
"#{message}#{errors}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Raised when GitHub returns a 400 HTTP status code
|
44
|
+
class BadRequest < Error; end
|
45
|
+
|
46
|
+
# Raised when GitHub returns a 401 HTTP status code
|
47
|
+
class Unauthorized < Error; end
|
48
|
+
|
49
|
+
# Raised when GitHub returns a 403 HTTP status code
|
50
|
+
class Forbidden < Error; end
|
51
|
+
|
52
|
+
# Raised when GitHub returns a 404 HTTP status code
|
53
|
+
class NotFound < Error; end
|
54
|
+
|
55
|
+
# Raised when GitHub returns a 406 HTTP status code
|
56
|
+
class NotAcceptable < Error; end
|
57
|
+
|
58
|
+
# Raised when GitHub returns a 422 HTTP status code
|
59
|
+
class UnprocessableEntity < Error; end
|
60
|
+
|
61
|
+
# Raised when GitHub returns a 500 HTTP status code
|
62
|
+
class InternalServerError < Error; end
|
63
|
+
|
64
|
+
# Raised when GitHub returns a 501 HTTP status code
|
65
|
+
class NotImplemented < Error; end
|
66
|
+
|
67
|
+
# Raised when GitHub returns a 502 HTTP status code
|
68
|
+
class BadGateway < Error; end
|
69
|
+
|
70
|
+
# Raised when GitHub returns a 503 HTTP status code
|
71
|
+
class ServiceUnavailable < Error; end
|
72
|
+
end
|
73
|
+
|
74
|
+
# @api private
|
75
|
+
module Faraday
|
76
|
+
class Response::RaiseGheeError < Response::Middleware
|
77
|
+
ERROR_MAP = {
|
78
|
+
400 => Ghee::BadRequest,
|
79
|
+
401 => Ghee::Unauthorized,
|
80
|
+
403 => Ghee::Forbidden,
|
81
|
+
406 => Ghee::NotAcceptable,
|
82
|
+
422 => Ghee::UnprocessableEntity,
|
83
|
+
500 => Ghee::InternalServerError,
|
84
|
+
501 => Ghee::NotImplemented,
|
85
|
+
502 => Ghee::BadGateway,
|
86
|
+
503 => Ghee::ServiceUnavailable
|
87
|
+
}
|
88
|
+
|
89
|
+
def on_complete(response)
|
90
|
+
key = response[:status].to_i
|
91
|
+
raise ERROR_MAP[key].new(response) if ERROR_MAP.has_key? key
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
data/lib/ghee/resource_proxy.rb
CHANGED
@@ -24,9 +24,11 @@ class Ghee
|
|
24
24
|
# connection - Ghee::Connection object
|
25
25
|
# path_prefix - String
|
26
26
|
#
|
27
|
-
def initialize(connection, path_prefix, params = {})
|
27
|
+
def initialize(connection, path_prefix, params = {}, &block)
|
28
28
|
params = {} if !params.is_a?Hash
|
29
29
|
@connection, @path_prefix, @params = connection, URI.escape(path_prefix), params
|
30
|
+
@block = block if block
|
31
|
+
subject if block
|
30
32
|
end
|
31
33
|
|
32
34
|
# Method_missing takes any message passed
|
@@ -54,7 +56,10 @@ class Ghee
|
|
54
56
|
# Returns json
|
55
57
|
#
|
56
58
|
def subject
|
57
|
-
@subject ||= connection.get(path_prefix)
|
59
|
+
@subject ||= connection.get(path_prefix) do |req|
|
60
|
+
req.params.merge!params
|
61
|
+
@block.call(req)if @block
|
62
|
+
end.body
|
58
63
|
end
|
59
64
|
|
60
65
|
# Paginate is a helper method to handle
|
@@ -93,6 +98,25 @@ class Ghee
|
|
93
98
|
self.all
|
94
99
|
end
|
95
100
|
|
101
|
+
def all_parallel
|
102
|
+
connection = @connection.parallel_connection
|
103
|
+
headers = connection.head(path_prefix) do |req|
|
104
|
+
req.params.merge! params.merge(:per_page => 100)
|
105
|
+
end
|
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
|
+
end
|
114
|
+
end
|
115
|
+
requests.inject([]) do |results, page|
|
116
|
+
results.concat(page.body)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
96
120
|
# Generate first_page, last_page, next_page, prev_page convienence methods
|
97
121
|
%w{ next prev first last }.each do |term|
|
98
122
|
define_method "#{term}_page" do
|
@@ -102,6 +126,16 @@ class Ghee
|
|
102
126
|
|
103
127
|
private
|
104
128
|
|
129
|
+
def pagination_data(header)
|
130
|
+
parse_link_header header
|
131
|
+
{ pages: @pagination[:last][:page] }
|
132
|
+
end
|
133
|
+
|
134
|
+
def build_prefix(first_argument, endpoint)
|
135
|
+
(!first_argument.is_a?(Hash) and first_argument) ?
|
136
|
+
"#{path_prefix}/#{endpoint}/#{first_argument}" : "#{path_prefix}/#{endpoint}"
|
137
|
+
end
|
138
|
+
|
105
139
|
def parse_link_header(header)
|
106
140
|
return @total = subject.size, @pagination = {} if header.nil?
|
107
141
|
require 'cgi'
|
data/lib/ghee/version.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ghee::API::Repos::Contents do
|
4
|
+
subject { Ghee.new(GH_AUTH).repos(GH_USER, GH_REPO) }
|
5
|
+
|
6
|
+
describe "#readme" do
|
7
|
+
it "should return the repos readme" do
|
8
|
+
VCR.use_cassette "repos#readme" do
|
9
|
+
readme = subject.readme
|
10
|
+
readme["name"].downcase.should == "readme.md"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return the repos readme" do
|
15
|
+
VCR.use_cassette "repos#readme#raw" do
|
16
|
+
readme = subject.readme do |req|
|
17
|
+
req.headers["Accept"] = "application/vnd.github.v3.raw"
|
18
|
+
end
|
19
|
+
readme.should be_instance_of String
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#contents" do
|
25
|
+
it "should return the content from a repo path" do
|
26
|
+
VCR.use_cassette "repos#contents(path)" do
|
27
|
+
readme = subject.contents("readme.md")
|
28
|
+
readme["path"].downcase.should == "readme.md"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
it "should create a new file in the repo" do
|
32
|
+
temp_file_name = "#{(0...8).map{ ('a'..'z').to_a[rand(26)] }.join}"
|
33
|
+
file = subject.contents("#{temp_file_name}.md").create(
|
34
|
+
message: "Adds #{temp_file_name}.md through the api",
|
35
|
+
content: "# Whoop whoop"
|
36
|
+
)
|
37
|
+
file['content']['type'].should == "file"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -10,8 +10,8 @@ describe Ghee::API::Events do
|
|
10
10
|
|
11
11
|
def should_be_an_event(event)
|
12
12
|
EventTypes.should include(event['type'])
|
13
|
-
event['repo'].should be_instance_of(
|
14
|
-
event['actor'].should be_instance_of(
|
13
|
+
event['repo'].should be_instance_of(Hash)
|
14
|
+
event['actor'].should be_instance_of(Hash)
|
15
15
|
event['created_at'].should_not be_nil
|
16
16
|
end
|
17
17
|
|
data/spec/ghee/api/gists_spec.rb
CHANGED
@@ -5,9 +5,9 @@ describe Ghee::API::Gists do
|
|
5
5
|
|
6
6
|
def should_be_a_gist(gist)
|
7
7
|
gist['url'].should include('https://api.github.com/gists/')
|
8
|
-
gist['
|
8
|
+
gist['owner']['url'].should include('https://api.github.com/users/')
|
9
9
|
gist['created_at'].should_not be_nil
|
10
|
-
gist['files'].should be_instance_of(
|
10
|
+
gist['files'].should be_instance_of(Hash)
|
11
11
|
gist['files'].size.should > 0
|
12
12
|
end
|
13
13
|
|
@@ -15,7 +15,7 @@ describe Ghee::API::Gists do
|
|
15
15
|
describe "#gists" do
|
16
16
|
it "should return users gists" do
|
17
17
|
VCR.use_cassette('users(login).gists') do
|
18
|
-
gists = subject.users(
|
18
|
+
gists = subject.users(GH_USER).gists
|
19
19
|
gists.size.should > 0
|
20
20
|
should_be_a_gist(gists.first)
|
21
21
|
end
|
@@ -28,8 +28,8 @@ describe Ghee::API::Repos::Issues do
|
|
28
28
|
it "should return open issues by default" do
|
29
29
|
VCR.use_cassette("repos(#{GH_USER},#{GH_REPO}).issues.search#default") do
|
30
30
|
issues = subject.repos(GH_USER, GH_REPO).issues.search("Seeded")
|
31
|
-
issues
|
32
|
-
should_be_an_issue(issues
|
31
|
+
issues['issues'].size.should > 0
|
32
|
+
should_be_an_issue(issues['issues'].first)
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
data/spec/ghee/api/repos_spec.rb
CHANGED
@@ -97,7 +97,7 @@ describe Ghee::API::Repos do
|
|
97
97
|
VCR.use_cassette("user.repos(#{GH_REPO})") do
|
98
98
|
repo = subject.user.repos(GH_REPO)
|
99
99
|
repo.connection.should_not be_nil
|
100
|
-
repo.path_prefix.should == "
|
100
|
+
repo.path_prefix.should == "./repos/#{GH_USER}/#{GH_REPO}"
|
101
101
|
should_be_a_repo(repo)
|
102
102
|
end
|
103
103
|
end
|
@@ -12,8 +12,8 @@ describe Ghee::API::Search do
|
|
12
12
|
it "should search open issues by repo by default" do
|
13
13
|
VCR.use_cassette "gh#search#issues#default" do
|
14
14
|
issues = subject.search.issues("#{GH_USER}/#{GH_REPO}", "Seeded")
|
15
|
-
issues
|
16
|
-
should_be_an_issue(issues
|
15
|
+
issues['issues'].size.should > 0
|
16
|
+
should_be_an_issue(issues['issues'].first)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/spec/ghee/api/users_spec.rb
CHANGED
@@ -47,7 +47,7 @@ describe Ghee::API::Users do
|
|
47
47
|
VCR.use_cassette "user.repos.public" do
|
48
48
|
repos = subject.user.repos :type => "public"
|
49
49
|
repos.size.should > 0
|
50
|
-
repos.path_prefix.should == "
|
50
|
+
repos.path_prefix.should == "./user/repos"
|
51
51
|
repos.should be_instance_of(Array)
|
52
52
|
repos.each do |r|
|
53
53
|
r["private"].should be_false
|
@@ -99,16 +99,16 @@ describe Ghee::API::Users do
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
describe "#emails" do
|
102
|
-
|
102
|
+
xit "should add and remove emails" do
|
103
103
|
VCR.use_cassette("user#emails") do
|
104
104
|
user = subject.user
|
105
105
|
emails = user.emails.add (["support@microsoft.com","octocat@microsoft.com"])
|
106
|
-
emails.should include("support@microsoft.com")
|
107
|
-
emails.should include("octocat@microsoft.com")
|
106
|
+
emails.map{ |e| e['email'] }.should include("support@microsoft.com")
|
107
|
+
emails.map{ |e| e['email'] }.should include("octocat@microsoft.com")
|
108
108
|
user.emails.remove(["support@microsoft.com","octocat@microsoft.com"]).should be_true
|
109
109
|
emails = user.emails
|
110
|
-
emails.should_not include("support@microsoft.com")
|
111
|
-
emails.should_not include("octocat@microsoft.com")
|
110
|
+
emails.map{ |e| e['email'] }.should_not include("support@microsoft.com")
|
111
|
+
emails.map{ |e| e['email'] }.should_not include("octocat@microsoft.com")
|
112
112
|
end
|
113
113
|
end
|
114
114
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'typhoeus'
|
3
|
+
require 'typhoeus/adapters/faraday'
|
4
|
+
require 'benchmark'
|
5
|
+
|
6
|
+
describe "testing concurrencies" do
|
7
|
+
subject { Ghee.new(GH_AUTH) }
|
8
|
+
|
9
|
+
xit "should make requests in parallel" do
|
10
|
+
Benchmark.bm do |b|
|
11
|
+
b.report do
|
12
|
+
subject.in_parallel :em_synchrony do |ghee|
|
13
|
+
puts ghee.connection.in_parallel?
|
14
|
+
5.times do |i|
|
15
|
+
ghee.repos("rauhryan/huboard").raw
|
16
|
+
ghee.repos("rauhryan/huboard").issues.raw
|
17
|
+
ghee.repos("rauhryan/huboard").issues.labels.raw
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
b.report do
|
22
|
+
ghee = subject
|
23
|
+
ghee.connection.adapter :typhoeus
|
24
|
+
puts ghee.connection.in_parallel?
|
25
|
+
5.times do |i|
|
26
|
+
ghee.repos("rauhryan/huboard").raw
|
27
|
+
ghee.repos("rauhryan/huboard").issues.raw
|
28
|
+
ghee.repos("rauhryan/huboard").issues.labels.raw
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
xit "play with paging" do
|
34
|
+
Benchmark.bm do |b|
|
35
|
+
b.report do
|
36
|
+
puts subject.repos("aspnet/mvc").issues.all_parallel.size
|
37
|
+
end
|
38
|
+
b.report do
|
39
|
+
puts subject.repos("aspnet/mvc").issues.all.size
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -10,6 +10,7 @@ VCR.config do |c|
|
|
10
10
|
c.cassette_library_dir = File.expand_path('../responses', __FILE__)
|
11
11
|
c.stub_with :webmock
|
12
12
|
c.default_cassette_options = {:record => :once}
|
13
|
+
c.allow_http_connections_when_no_cassette = true
|
13
14
|
end
|
14
15
|
if File.exists? File.expand_path("../settings.yml", __FILE__)
|
15
16
|
settings = YAML.load_file(File.expand_path('../settings.yml', __FILE__))
|
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.10.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Rauh
|
@@ -9,194 +9,202 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-01-
|
12
|
+
date: 2015-01-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '0.9'
|
21
|
-
- - '>='
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: '0.8'
|
24
21
|
type: :runtime
|
25
22
|
prerelease: false
|
26
23
|
version_requirements: !ruby/object:Gem::Requirement
|
27
24
|
requirements:
|
28
|
-
- -
|
25
|
+
- - "~>"
|
29
26
|
- !ruby/object:Gem::Version
|
30
27
|
version: '0.9'
|
31
|
-
- - '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.8'
|
34
28
|
- !ruby/object:Gem::Dependency
|
35
29
|
name: faraday_middleware
|
36
30
|
requirement: !ruby/object:Gem::Requirement
|
37
31
|
requirements:
|
38
|
-
- - ~>
|
32
|
+
- - "~>"
|
39
33
|
- !ruby/object:Gem::Version
|
40
34
|
version: '0.9'
|
41
35
|
type: :runtime
|
42
36
|
prerelease: false
|
43
37
|
version_requirements: !ruby/object:Gem::Requirement
|
44
38
|
requirements:
|
45
|
-
- - ~>
|
39
|
+
- - "~>"
|
46
40
|
- !ruby/object:Gem::Version
|
47
41
|
version: '0.9'
|
48
42
|
- !ruby/object:Gem::Dependency
|
49
43
|
name: hashie
|
50
44
|
requirement: !ruby/object:Gem::Requirement
|
51
45
|
requirements:
|
52
|
-
- - ~>
|
46
|
+
- - "~>"
|
53
47
|
- !ruby/object:Gem::Version
|
54
48
|
version: 3.3.2
|
55
49
|
type: :runtime
|
56
50
|
prerelease: false
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
58
52
|
requirements:
|
59
|
-
- - ~>
|
53
|
+
- - "~>"
|
60
54
|
- !ruby/object:Gem::Version
|
61
55
|
version: 3.3.2
|
62
56
|
- !ruby/object:Gem::Dependency
|
63
57
|
name: multi_json
|
64
58
|
requirement: !ruby/object:Gem::Requirement
|
65
59
|
requirements:
|
66
|
-
- - ~>
|
60
|
+
- - "~>"
|
67
61
|
- !ruby/object:Gem::Version
|
68
62
|
version: '1.3'
|
69
63
|
type: :runtime
|
70
64
|
prerelease: false
|
71
65
|
version_requirements: !ruby/object:Gem::Requirement
|
72
66
|
requirements:
|
73
|
-
- - ~>
|
67
|
+
- - "~>"
|
74
68
|
- !ruby/object:Gem::Version
|
75
69
|
version: '1.3'
|
76
70
|
- !ruby/object:Gem::Dependency
|
77
71
|
name: highline
|
78
72
|
requirement: !ruby/object:Gem::Requirement
|
79
73
|
requirements:
|
80
|
-
- - ~>
|
74
|
+
- - "~>"
|
81
75
|
- !ruby/object:Gem::Version
|
82
76
|
version: 1.6.15
|
83
77
|
type: :runtime
|
84
78
|
prerelease: false
|
85
79
|
version_requirements: !ruby/object:Gem::Requirement
|
86
80
|
requirements:
|
87
|
-
- - ~>
|
81
|
+
- - "~>"
|
88
82
|
- !ruby/object:Gem::Version
|
89
83
|
version: 1.6.15
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: typhoeus
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 0.7.0
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 0.7.0
|
90
98
|
- !ruby/object:Gem::Dependency
|
91
99
|
name: rake
|
92
100
|
requirement: !ruby/object:Gem::Requirement
|
93
101
|
requirements:
|
94
|
-
- -
|
102
|
+
- - ">="
|
95
103
|
- !ruby/object:Gem::Version
|
96
104
|
version: '0'
|
97
105
|
type: :development
|
98
106
|
prerelease: false
|
99
107
|
version_requirements: !ruby/object:Gem::Requirement
|
100
108
|
requirements:
|
101
|
-
- -
|
109
|
+
- - ">="
|
102
110
|
- !ruby/object:Gem::Version
|
103
111
|
version: '0'
|
104
112
|
- !ruby/object:Gem::Dependency
|
105
113
|
name: json_pure
|
106
114
|
requirement: !ruby/object:Gem::Requirement
|
107
115
|
requirements:
|
108
|
-
- -
|
116
|
+
- - ">="
|
109
117
|
- !ruby/object:Gem::Version
|
110
118
|
version: '0'
|
111
119
|
type: :development
|
112
120
|
prerelease: false
|
113
121
|
version_requirements: !ruby/object:Gem::Requirement
|
114
122
|
requirements:
|
115
|
-
- -
|
123
|
+
- - ">="
|
116
124
|
- !ruby/object:Gem::Version
|
117
125
|
version: '0'
|
118
126
|
- !ruby/object:Gem::Dependency
|
119
127
|
name: rspec
|
120
128
|
requirement: !ruby/object:Gem::Requirement
|
121
129
|
requirements:
|
122
|
-
- - ~>
|
130
|
+
- - "~>"
|
123
131
|
- !ruby/object:Gem::Version
|
124
132
|
version: 2.9.0
|
125
133
|
type: :development
|
126
134
|
prerelease: false
|
127
135
|
version_requirements: !ruby/object:Gem::Requirement
|
128
136
|
requirements:
|
129
|
-
- - ~>
|
137
|
+
- - "~>"
|
130
138
|
- !ruby/object:Gem::Version
|
131
139
|
version: 2.9.0
|
132
140
|
- !ruby/object:Gem::Dependency
|
133
141
|
name: webmock
|
134
142
|
requirement: !ruby/object:Gem::Requirement
|
135
143
|
requirements:
|
136
|
-
- -
|
144
|
+
- - ">="
|
137
145
|
- !ruby/object:Gem::Version
|
138
146
|
version: '0'
|
139
147
|
type: :development
|
140
148
|
prerelease: false
|
141
149
|
version_requirements: !ruby/object:Gem::Requirement
|
142
150
|
requirements:
|
143
|
-
- -
|
151
|
+
- - ">="
|
144
152
|
- !ruby/object:Gem::Version
|
145
153
|
version: '0'
|
146
154
|
- !ruby/object:Gem::Dependency
|
147
155
|
name: vcr
|
148
156
|
requirement: !ruby/object:Gem::Requirement
|
149
157
|
requirements:
|
150
|
-
- -
|
158
|
+
- - ">="
|
151
159
|
- !ruby/object:Gem::Version
|
152
160
|
version: '0'
|
153
161
|
type: :development
|
154
162
|
prerelease: false
|
155
163
|
version_requirements: !ruby/object:Gem::Requirement
|
156
164
|
requirements:
|
157
|
-
- -
|
165
|
+
- - ">="
|
158
166
|
- !ruby/object:Gem::Version
|
159
167
|
version: '0'
|
160
168
|
- !ruby/object:Gem::Dependency
|
161
169
|
name: ZenTest
|
162
170
|
requirement: !ruby/object:Gem::Requirement
|
163
171
|
requirements:
|
164
|
-
- -
|
172
|
+
- - ">="
|
165
173
|
- !ruby/object:Gem::Version
|
166
174
|
version: '0'
|
167
175
|
type: :development
|
168
176
|
prerelease: false
|
169
177
|
version_requirements: !ruby/object:Gem::Requirement
|
170
178
|
requirements:
|
171
|
-
- -
|
179
|
+
- - ">="
|
172
180
|
- !ruby/object:Gem::Version
|
173
181
|
version: '0'
|
174
182
|
- !ruby/object:Gem::Dependency
|
175
183
|
name: autotest-growl
|
176
184
|
requirement: !ruby/object:Gem::Requirement
|
177
185
|
requirements:
|
178
|
-
- -
|
186
|
+
- - ">="
|
179
187
|
- !ruby/object:Gem::Version
|
180
188
|
version: '0'
|
181
189
|
type: :development
|
182
190
|
prerelease: false
|
183
191
|
version_requirements: !ruby/object:Gem::Requirement
|
184
192
|
requirements:
|
185
|
-
- -
|
193
|
+
- - ">="
|
186
194
|
- !ruby/object:Gem::Version
|
187
195
|
version: '0'
|
188
196
|
- !ruby/object:Gem::Dependency
|
189
197
|
name: uuidtools
|
190
198
|
requirement: !ruby/object:Gem::Requirement
|
191
199
|
requirements:
|
192
|
-
- -
|
200
|
+
- - ">="
|
193
201
|
- !ruby/object:Gem::Version
|
194
202
|
version: '0'
|
195
203
|
type: :development
|
196
204
|
prerelease: false
|
197
205
|
version_requirements: !ruby/object:Gem::Requirement
|
198
206
|
requirements:
|
199
|
-
- -
|
207
|
+
- - ">="
|
200
208
|
- !ruby/object:Gem::Version
|
201
209
|
version: '0'
|
202
210
|
description: A complete, simple, and intuitive ruby API for all things Github.
|
@@ -207,9 +215,10 @@ executables:
|
|
207
215
|
extensions: []
|
208
216
|
extra_rdoc_files: []
|
209
217
|
files:
|
210
|
-
- .autotest
|
211
|
-
- .gitignore
|
212
|
-
- .
|
218
|
+
- ".autotest"
|
219
|
+
- ".gitignore"
|
220
|
+
- ".ruby-version"
|
221
|
+
- ".travis.yml"
|
213
222
|
- Gemfile
|
214
223
|
- LICENSE
|
215
224
|
- README.md
|
@@ -220,6 +229,7 @@ files:
|
|
220
229
|
- lib/ghee/api/authorizations.rb
|
221
230
|
- lib/ghee/api/collaborators.rb
|
222
231
|
- lib/ghee/api/commits.rb
|
232
|
+
- lib/ghee/api/contents.rb
|
223
233
|
- lib/ghee/api/downloads.rb
|
224
234
|
- lib/ghee/api/emails.rb
|
225
235
|
- lib/ghee/api/events.rb
|
@@ -239,14 +249,15 @@ files:
|
|
239
249
|
- lib/ghee/api/users.rb
|
240
250
|
- lib/ghee/api/watchers.rb
|
241
251
|
- lib/ghee/connection.rb
|
252
|
+
- lib/ghee/errors.rb
|
242
253
|
- lib/ghee/resource_proxy.rb
|
243
254
|
- lib/ghee/state_methods.rb
|
244
255
|
- lib/ghee/uri_escape.rb
|
245
256
|
- lib/ghee/version.rb
|
246
|
-
- spec/fyeah.jpg
|
247
257
|
- spec/ghee/api/authorizations_spec.rb
|
248
258
|
- spec/ghee/api/collaborators_spec.rb
|
249
|
-
- spec/ghee/api/
|
259
|
+
- spec/ghee/api/contents_spec.rb
|
260
|
+
- spec/ghee/api/downloads_spec.rb.ignore
|
250
261
|
- spec/ghee/api/events_spec.rb
|
251
262
|
- spec/ghee/api/gists_spec.rb
|
252
263
|
- spec/ghee/api/gitdata_spec.rb
|
@@ -258,6 +269,7 @@ files:
|
|
258
269
|
- spec/ghee/api/search_spec.rb
|
259
270
|
- spec/ghee/api/teams_spec.rb
|
260
271
|
- spec/ghee/api/users_spec.rb
|
272
|
+
- spec/ghee/concurrency_spec.rb
|
261
273
|
- spec/ghee/connection_spec.rb
|
262
274
|
- spec/ghee/memory_cache_spec.rb
|
263
275
|
- spec/ghee/resource_proxy_spec.rb
|
@@ -274,25 +286,25 @@ require_paths:
|
|
274
286
|
- lib
|
275
287
|
required_ruby_version: !ruby/object:Gem::Requirement
|
276
288
|
requirements:
|
277
|
-
- -
|
289
|
+
- - ">="
|
278
290
|
- !ruby/object:Gem::Version
|
279
291
|
version: '0'
|
280
292
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
281
293
|
requirements:
|
282
|
-
- -
|
294
|
+
- - ">="
|
283
295
|
- !ruby/object:Gem::Version
|
284
296
|
version: '0'
|
285
297
|
requirements: []
|
286
298
|
rubyforge_project: ghee
|
287
|
-
rubygems_version: 2.
|
299
|
+
rubygems_version: 2.2.2
|
288
300
|
signing_key:
|
289
301
|
specification_version: 4
|
290
302
|
summary: Access Github in ruby.
|
291
303
|
test_files:
|
292
|
-
- spec/fyeah.jpg
|
293
304
|
- spec/ghee/api/authorizations_spec.rb
|
294
305
|
- spec/ghee/api/collaborators_spec.rb
|
295
|
-
- spec/ghee/api/
|
306
|
+
- spec/ghee/api/contents_spec.rb
|
307
|
+
- spec/ghee/api/downloads_spec.rb.ignore
|
296
308
|
- spec/ghee/api/events_spec.rb
|
297
309
|
- spec/ghee/api/gists_spec.rb
|
298
310
|
- spec/ghee/api/gitdata_spec.rb
|
@@ -304,6 +316,7 @@ test_files:
|
|
304
316
|
- spec/ghee/api/search_spec.rb
|
305
317
|
- spec/ghee/api/teams_spec.rb
|
306
318
|
- spec/ghee/api/users_spec.rb
|
319
|
+
- spec/ghee/concurrency_spec.rb
|
307
320
|
- spec/ghee/connection_spec.rb
|
308
321
|
- spec/ghee/memory_cache_spec.rb
|
309
322
|
- spec/ghee/resource_proxy_spec.rb
|
data/spec/fyeah.jpg
DELETED
Binary file
|