github_api 0.9.1 → 0.9.2

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.
@@ -77,7 +77,7 @@ module Github
77
77
  def method_missing(method, *args, &block) # :nodoc:
78
78
  case method.to_s
79
79
  when /^(.*)\?$/
80
- return !self.send($1.to_s).nil?
80
+ return !!self.send($1.to_s)
81
81
  when /^clear_(.*)$/
82
82
  self.send("#{$1.to_s}=", nil)
83
83
  else
@@ -8,6 +8,8 @@ module Github
8
8
  include ParameterFilter
9
9
  include Validations
10
10
 
11
+ AUTO_PAGINATION = 'auto_pagination'.freeze
12
+
11
13
  # Parameters passed to request
12
14
  attr_reader :params
13
15
 
@@ -54,6 +56,7 @@ module Github
54
56
  end
55
57
  @params = options
56
58
  @remaining = extract_remaining(args)
59
+ extract_pagination(options)
57
60
  yield_or_eval(&block)
58
61
  self
59
62
  end
@@ -100,6 +103,14 @@ module Github
100
103
  args[required.size..-1]
101
104
  end
102
105
 
106
+ # Fine auto_pagination parameter in options hash
107
+ #
108
+ def extract_pagination(options)
109
+ if (value = options.delete(AUTO_PAGINATION))
110
+ api.auto_pagination = value
111
+ end
112
+ end
113
+
103
114
  # Remove required arguments from parameters and
104
115
  # validate their presence(if not nil or empty string).
105
116
  #
@@ -19,7 +19,8 @@ module Github
19
19
  :org,
20
20
  :login,
21
21
  :password,
22
- :basic_auth
22
+ :basic_auth,
23
+ :auto_pagination
23
24
  ].freeze
24
25
 
25
26
  # Other adapters are :typhoeus, :patron, :em_synchrony, :excon, :test
@@ -70,6 +71,9 @@ module Github
70
71
  # By default, don't set organization name
71
72
  DEFAULT_ORG = nil
72
73
 
74
+ # By default, don't traverse the page links
75
+ DEFAULT_AUTO_PAGINATION = false
76
+
73
77
  attr_accessor *VALID_OPTIONS_KEYS
74
78
 
75
79
  # Convenience method to allow for global setting of configuration options
@@ -112,6 +116,7 @@ module Github
112
116
  self.login = DEFAULT_LOGIN
113
117
  self.password = DEFAULT_PASSWORD
114
118
  self.basic_auth = DEFAULT_BASIC_AUTH
119
+ self.auto_pagination = DEFAULT_AUTO_PAGINATION
115
120
  self
116
121
  end
117
122
 
@@ -16,6 +16,21 @@ module Github
16
16
  page_iterator.count.to_i
17
17
  end
18
18
 
19
+ # Iterate over results set pages by automatically calling `next_page`
20
+ # until all pages are exhausted. Caution needs to be exercised when
21
+ # using this feature - 100 pages iteration will perform 100 API calls.
22
+ # By default this is off. You can set it on the client, individual API
23
+ # instances or just per given request.
24
+ #
25
+ def auto_paginate(auto=false)
26
+ if current_api.auto_pagination? || auto
27
+ resources_bodies = []
28
+ each_page { |resource| resources_bodies += resource.body }
29
+ self.body = resources_bodies
30
+ end
31
+ self
32
+ end
33
+
19
34
  # Iterator like each for response pages. If there are no pages to
20
35
  # iterate over this method will return current page.
21
36
  def each_page
@@ -32,7 +32,6 @@ module Github
32
32
  if !METHODS.include?(method)
33
33
  raise ArgumentError, "unkown http method: #{method}"
34
34
  end
35
- # _extract_mime_type(params, options)
36
35
 
37
36
  puts "EXECUTED: #{method} - #{path} with #{params} and #{options}" if ENV['DEBUG']
38
37
 
@@ -51,7 +50,7 @@ module Github
51
50
  request.body = extract_data_from_params(params) unless params.empty?
52
51
  end
53
52
  end
54
- ResponseWrapper.new(response, self)
53
+ ResponseWrapper.new(response, self).auto_paginate
55
54
  end
56
55
 
57
56
  private
@@ -28,10 +28,15 @@ module Github
28
28
  response.env[:url].to_s
29
29
  end
30
30
 
31
+ def body=(value)
32
+ @body = value
33
+ @env[:body] = value
34
+ end
35
+
31
36
  # Response raw body
32
37
  #
33
38
  def body
34
- response.body
39
+ @body ? @body : response.body
35
40
  end
36
41
 
37
42
  # Response status
@@ -44,17 +49,33 @@ module Github
44
49
  response.success?
45
50
  end
46
51
 
52
+ def redirect?
53
+ status.to_i >= 300 && status.to_i < 400
54
+ end
55
+
56
+ def client_error?
57
+ status.to_i >= 400 && status.to_i < 500
58
+ end
59
+
60
+ def server_error?
61
+ status.to_i >= 500 && status.to_i < 600
62
+ end
63
+
47
64
  # Return response headers
48
65
  #
49
66
  def headers
50
67
  Github::Response::Header.new(env)
51
68
  end
52
69
 
53
- # Lookup an attribute from the body.
70
+ # Lookup an attribute from the body if hash, otherwise behave like array index.
54
71
  # Convert any key to string before calling.
55
72
  #
56
73
  def [](key)
57
- self.body.send(:"#{key}")
74
+ if self.body.is_a?(Array)
75
+ self.body[key]
76
+ else
77
+ self.body.send(:"#{key}")
78
+ end
58
79
  end
59
80
 
60
81
  # Return response body as string
@@ -86,7 +107,7 @@ module Github
86
107
  # Check if body has an attribute
87
108
  #
88
109
  def has_key?(key)
89
- !self.body.is_a?(Array) && self.body.has_key?(key)
110
+ self.body.is_a?(Hash) && self.body.has_key?(key)
90
111
  end
91
112
 
92
113
  # Coerce any method calls for body attributes
@@ -18,6 +18,7 @@ module Github
18
18
  VALID_API_KEYS = [
19
19
  'page',
20
20
  'per_page',
21
+ 'auto_pagination',
21
22
  'jsonp_callback'
22
23
  ]
23
24
 
@@ -4,7 +4,7 @@ module Github
4
4
  module VERSION
5
5
  MAJOR = 0
6
6
  MINOR = 9
7
- PATCH = 1
7
+ PATCH = 2
8
8
  BUILD = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.');
@@ -1,4 +1,5 @@
1
1
  require 'simplecov'
2
+ require 'coveralls'
2
3
 
3
4
  SimpleCov.adapters.define 'github_api' do
4
5
  add_filter "/spec/"
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Configuration do
6
+ let(:klass) {
7
+ ::Class.new do
8
+ extend Github::Configuration
9
+ end
10
+ }
11
+
12
+ subject { klass }
13
+
14
+ its(:adapter) { should == described_class::DEFAULT_ADAPTER }
15
+
16
+ its(:endpoint) { should == described_class::DEFAULT_ENDPOINT }
17
+
18
+ its(:site) { should == described_class::DEFAULT_SITE }
19
+
20
+ its(:user_agent) { should == described_class::DEFAULT_USER_AGENT }
21
+
22
+ its(:oauth_token) { should be_nil }
23
+
24
+ its(:auto_pagination) { should == described_class::DEFAULT_AUTO_PAGINATION }
25
+
26
+ its(:auto_pagination) { should be_false }
27
+
28
+ its(:ssl) { should == described_class::DEFAULT_SSL }
29
+
30
+ its(:ssl) { should be_a Hash }
31
+
32
+ its(:user_agent) { should == described_class::DEFAULT_USER_AGENT }
33
+
34
+ its(:repo) { should be_nil }
35
+
36
+ its(:user) { should be_nil }
37
+
38
+ its(:connection_options) { should be_a Hash }
39
+
40
+ its(:connection_options) { should be_empty }
41
+
42
+ its(:login) { should == described_class::DEFAULT_LOGIN }
43
+
44
+ its(:password) { should == described_class::DEFAULT_PASSWORD }
45
+
46
+ describe ".configure" do
47
+ it { should respond_to :configure }
48
+
49
+ described_class.keys.each do |key|
50
+ it "should set the #{key}" do
51
+ subject.configure do |config|
52
+ config.send("#{key}=", key)
53
+ subject.send(key).should == key
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ end
@@ -38,10 +38,6 @@ describe Github::Repos::PubSubHubbub, '#subscribe' do
38
38
  subject.subscribe topic, callback
39
39
  a_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs).should have_been_made
40
40
  end
41
-
42
- it "" do
43
- subject.subscribe(topic, callback)
44
- end
45
41
  end
46
42
 
47
43
  it_should_behave_like 'request failure' do
@@ -3,108 +3,13 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Github do
6
-
7
- after do
6
+ after {
8
7
  subject.reset!
9
8
  reset_authentication_for subject
10
- end
11
-
12
- it "should respond to 'new' message" do
13
- subject.should respond_to :new
14
- end
15
-
16
- it "should receive 'new' and initialize subject::Client instance" do
17
- subject.new.should be_a Github::Client
18
- end
19
-
20
- it "should respond to 'configure' message" do
21
- subject.should respond_to :configure
22
- end
23
-
24
- describe "setting configuration options" do
25
- it "should return default adapter" do
26
- subject.adapter.should == Github::Configuration::DEFAULT_ADAPTER
27
- end
28
-
29
- it "should allow to set adapter" do
30
- subject.adapter = :typhoeus
31
- subject.adapter.should == :typhoeus
32
- end
33
-
34
- it "should return the default end point" do
35
- subject.endpoint.should == Github::Configuration::DEFAULT_ENDPOINT
36
- end
37
-
38
- it "should allow to set endpoint" do
39
- subject.endpoint = 'http://linkedin.com'
40
- subject.endpoint.should == 'http://linkedin.com'
41
- end
42
-
43
- it "should return the default user agent" do
44
- subject.user_agent.should == Github::Configuration::DEFAULT_USER_AGENT
45
- end
46
-
47
- it "should allow to set new user agent" do
48
- subject.user_agent = 'New User Agent'
49
- subject.user_agent.should == 'New User Agent'
50
- end
51
-
52
- it "should have not set oauth token" do
53
- subject.oauth_token.should be_nil
54
- end
55
-
56
- it "should allow to set oauth token" do
57
- subject.oauth_token = ''
58
- end
59
-
60
- it "should have not set default user" do
61
- subject.user.should be_nil
62
- end
63
-
64
- it "should allow to set new user" do
65
- subject.user = 'github'
66
- subject.user.should == 'github'
67
- end
68
-
69
- it "should have not set default repository" do
70
- subject.repo.should be_nil
71
- end
72
-
73
- it "should allow to set new repository" do
74
- subject.repo = 'github'
75
- subject.repo.should == 'github'
76
- end
77
-
78
- it "should have connection options as hash" do
79
- subject.connection_options.should be_a Hash
80
- end
81
-
82
- it "should initialize connection options to empty hash" do
83
- subject.connection_options.should be_empty
84
- end
85
-
86
- it "shoulve have not set user's login" do
87
- subject.login.should be_nil
88
- end
89
-
90
- it "should have not set user's password" do
91
- subject.password.should be_nil
92
- end
9
+ }
93
10
 
94
- it "should have set mime type to json" do
95
- subject.mime_type.should == :json
96
- end
97
- end
11
+ it { should respond_to :new }
98
12
 
99
- describe ".configure" do
100
- Github::Configuration::VALID_OPTIONS_KEYS.each do |key|
101
- it "should set the #{key}" do
102
- Github.configure do |config|
103
- config.send("#{key}=", key)
104
- Github.send(key).should == key
105
- end
106
- end
107
- end
108
- end
13
+ it { expect(subject.new).to be_a Github::Client }
109
14
 
110
15
  end # Github
@@ -72,5 +72,9 @@ describe 'Arguments' do
72
72
  subject.milestone_id.should == milestone_id
73
73
  end
74
74
 
75
+ it "passes through extra parameters" do
76
+ subject.get user, repo, milestone_id, :auto_pagination => true
77
+ end
78
+
75
79
  end
76
80
  end
@@ -8,8 +8,12 @@ require 'json'
8
8
  require 'webmock/rspec'
9
9
  require 'github_api'
10
10
 
11
- if RUBY_VERSION > '1.9' and ENV['COVERAGE']
11
+ if RUBY_VERSION > '1.9' and (ENV['COVERAGE'] || ENV['TRAVIS'])
12
12
  require 'coverage_adapter'
13
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
14
+ SimpleCov::Formatter::HTMLFormatter,
15
+ Coveralls::SimpleCov::Formatter
16
+ ]
13
17
  SimpleCov.start 'github_api'
14
18
  SimpleCov.coverage_dir 'coverage/rspec'
15
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-24 00:00:00.000000000Z
12
+ date: 2013-03-03 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashie
16
- requirement: &2154681220 !ruby/object:Gem::Requirement
16
+ requirement: &2155174360 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2154681220
24
+ version_requirements: *2155174360
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: faraday
27
- requirement: &2154680720 !ruby/object:Gem::Requirement
27
+ requirement: &2155173860 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.8.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2154680720
35
+ version_requirements: *2155173860
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: multi_json
38
- requirement: &2154680260 !ruby/object:Gem::Requirement
38
+ requirement: &2155173400 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '1.4'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2154680260
46
+ version_requirements: *2155173400
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: oauth2
49
- requirement: &2154679880 !ruby/object:Gem::Requirement
49
+ requirement: &2155173020 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2154679880
57
+ version_requirements: *2155173020
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: nokogiri
60
- requirement: &2154679340 !ruby/object:Gem::Requirement
60
+ requirement: &2155172480 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.5.2
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *2154679340
68
+ version_requirements: *2155172480
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &2154678840 !ruby/object:Gem::Requirement
71
+ requirement: &2155171980 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2154678840
79
+ version_requirements: *2155171980
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: cucumber
82
- requirement: &2154678380 !ruby/object:Gem::Requirement
82
+ requirement: &2155171520 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2154678380
90
+ version_requirements: *2155171520
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: webmock
93
- requirement: &2154667660 !ruby/object:Gem::Requirement
93
+ requirement: &2155171060 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 1.9.0
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2154667660
101
+ version_requirements: *2155171060
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: vcr
104
- requirement: &2154667200 !ruby/object:Gem::Requirement
104
+ requirement: &2155170600 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 2.4.0
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *2154667200
112
+ version_requirements: *2155170600
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: simplecov
115
- requirement: &2154666740 !ruby/object:Gem::Requirement
115
+ requirement: &2155170140 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,10 +120,21 @@ dependencies:
120
120
  version: 0.7.1
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *2154666740
123
+ version_requirements: *2155170140
124
+ - !ruby/object:Gem::Dependency
125
+ name: coveralls
126
+ requirement: &2155169680 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 0.5.8
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: *2155169680
124
135
  - !ruby/object:Gem::Dependency
125
136
  name: guard
126
- requirement: &2154666360 !ruby/object:Gem::Requirement
137
+ requirement: &2155169300 !ruby/object:Gem::Requirement
127
138
  none: false
128
139
  requirements:
129
140
  - - ! '>='
@@ -131,10 +142,10 @@ dependencies:
131
142
  version: '0'
132
143
  type: :development
133
144
  prerelease: false
134
- version_requirements: *2154666360
145
+ version_requirements: *2155169300
135
146
  - !ruby/object:Gem::Dependency
136
147
  name: guard-rspec
137
- requirement: &2154665900 !ruby/object:Gem::Requirement
148
+ requirement: &2155168840 !ruby/object:Gem::Requirement
138
149
  none: false
139
150
  requirements:
140
151
  - - ! '>='
@@ -142,10 +153,10 @@ dependencies:
142
153
  version: '0'
143
154
  type: :development
144
155
  prerelease: false
145
- version_requirements: *2154665900
156
+ version_requirements: *2155168840
146
157
  - !ruby/object:Gem::Dependency
147
158
  name: guard-cucumber
148
- requirement: &2154665480 !ruby/object:Gem::Requirement
159
+ requirement: &2155168420 !ruby/object:Gem::Requirement
149
160
  none: false
150
161
  requirements:
151
162
  - - ! '>='
@@ -153,10 +164,10 @@ dependencies:
153
164
  version: '0'
154
165
  type: :development
155
166
  prerelease: false
156
- version_requirements: *2154665480
167
+ version_requirements: *2155168420
157
168
  - !ruby/object:Gem::Dependency
158
169
  name: rake
159
- requirement: &2154665060 !ruby/object:Gem::Requirement
170
+ requirement: &2155168000 !ruby/object:Gem::Requirement
160
171
  none: false
161
172
  requirements:
162
173
  - - ! '>='
@@ -164,10 +175,10 @@ dependencies:
164
175
  version: '0'
165
176
  type: :development
166
177
  prerelease: false
167
- version_requirements: *2154665060
178
+ version_requirements: *2155168000
168
179
  - !ruby/object:Gem::Dependency
169
180
  name: bundler
170
- requirement: &2154664640 !ruby/object:Gem::Requirement
181
+ requirement: &2155167580 !ruby/object:Gem::Requirement
171
182
  none: false
172
183
  requirements:
173
184
  - - ! '>='
@@ -175,7 +186,7 @@ dependencies:
175
186
  version: '0'
176
187
  type: :development
177
188
  prerelease: false
178
- version_requirements: *2154664640
189
+ version_requirements: *2155167580
179
190
  description: ! ' Ruby wrapper that supports all of the GitHub API v3 methods(nearly
180
191
  200). It''s build in a modular way, that is, you can either instantiate the whole
181
192
  api wrapper Github.new or use parts of it e.i. Github::Repos.new if working solely
@@ -190,6 +201,7 @@ files:
190
201
  - features/activity/notifications.feature
191
202
  - features/activity/starring.feature
192
203
  - features/activity/watching.feature
204
+ - features/auto_pagination.feature
193
205
  - features/cassettes/activity/events/issue.yml
194
206
  - features/cassettes/activity/events/network.yml
195
207
  - features/cassettes/activity/events/org.yml
@@ -209,6 +221,8 @@ files:
209
221
  - features/cassettes/activity/watching/watch.yml
210
222
  - features/cassettes/activity/watching/watched.yml
211
223
  - features/cassettes/activity/watching/watching.yml
224
+ - features/cassettes/auto_pagination/repos/global_list.yml
225
+ - features/cassettes/auto_pagination/repos/list.yml
212
226
  - features/cassettes/emojis/list.yml
213
227
  - features/cassettes/errors/repos/create.yml
214
228
  - features/cassettes/gists/comments/all.yml
@@ -594,6 +608,7 @@ files:
594
608
  - spec/github/authorizations/list_spec.rb
595
609
  - spec/github/authorizations/update_spec.rb
596
610
  - spec/github/client_spec.rb
611
+ - spec/github/configuration_spec.rb
597
612
  - spec/github/core_ext/hash_spec.rb
598
613
  - spec/github/deprecation_spec.rb
599
614
  - spec/github/error/client_error_spec.rb