github_api 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -111,6 +111,29 @@ github.git_data.trees.get 'peter-murach', 'github', 'c18647b75d72f19c1e0cc8af031
111
111
  end
112
112
  ```
113
113
 
114
+ ## Advanced Configuration
115
+
116
+ The `github_api` gem will use the default middleware stack which is exposed by calling `stack` on client instance. However, this stack can be freely modified with methods such as `insert`, `insert_after`, `delete` and `swap`. For instance to add your `CustomMiddleware` do
117
+
118
+ ```ruby
119
+ github = Github.new do |config|
120
+ config.stack.insert_after Github::Response::Helpers, CustomMiddleware
121
+ end
122
+ ```
123
+
124
+ Furthermore, you can build your entire custom stack and specify other connection options such as `adapter`
125
+
126
+ ```ruby
127
+ github = Github.new do |config|
128
+ config.adapter :excon
129
+
130
+ config.stack do |builder|
131
+ builder.use Github::Response::Helpers
132
+ builder.use Github::Response::Jsonize
133
+ end
134
+ end
135
+ ```
136
+
114
137
  ## API
115
138
 
116
139
  Main API methods are grouped into the following classes that can be instantiated on their own
@@ -229,23 +252,6 @@ Github.new(:basic_auth => 'login:password')
229
252
 
230
253
  All parameters can be overwirtten as per method call. By passing parameters hash...
231
254
 
232
- ## Stack(work in progress)
233
-
234
- By default the `github_api` gem will use the default middleware stack. However, a simple DSL is provided to create a custom stack, for instance:
235
-
236
- ```ruby
237
- github = Github.stack do
238
- request :filter
239
- request :normalizer
240
- request :validations
241
-
242
- response :cache do
243
- register :filestore
244
- end
245
-
246
- adapter :net_http
247
- end
248
- ```
249
255
 
250
256
  By default no caching will be performed. In order to set the cache do... If no cache type is provided a default memoization is done.
251
257
 
@@ -40,26 +40,26 @@ module Github
40
40
  # Creates new API
41
41
  def initialize(options={}, &block)
42
42
  super()
43
- options = Github.options.merge(options)
44
-
45
- Configuration::VALID_OPTIONS_KEYS.each do |key|
46
- send("#{key}=", options[key])
47
- end
48
- _process_basic_auth(options[:basic_auth])
49
- _set_api_client
43
+ setup options
44
+ set_api_client
50
45
  client if client_id? && client_secret?
51
46
 
52
47
  self.instance_eval(&block) if block_given?
53
48
  end
54
49
 
55
- private
50
+ def setup(options={})
51
+ options = Github.options.merge(options)
52
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
53
+ send("#{key}=", options[key])
54
+ end
55
+ process_basic_auth(options[:basic_auth])
56
+ end
56
57
 
57
58
  # Extract login and password from basic_auth parameter
58
- def _process_basic_auth(auth)
59
+ def process_basic_auth(auth)
59
60
  case auth
60
61
  when String
61
- self.login = auth.split(':').first
62
- self.password = auth.split(':').last
62
+ self.login, self.password = auth.split(':', 2)
63
63
  when Hash
64
64
  self.login = auth[:login]
65
65
  self.password = auth[:password]
@@ -67,7 +67,7 @@ module Github
67
67
  end
68
68
 
69
69
  # Assigns current api class
70
- def _set_api_client
70
+ def set_api_client
71
71
  Github.api_client = self
72
72
  end
73
73
 
@@ -23,7 +23,7 @@ module Github
23
23
  :ssl
24
24
  ].freeze
25
25
 
26
- def default_options(options={}) # :nodoc:
26
+ def default_options(options={})
27
27
  {
28
28
  :headers => {
29
29
  ACCEPT => "application/vnd.github.v3.raw+json," \
@@ -31,50 +31,68 @@ module Github
31
31
  "application/json;q=0.1",
32
32
  ACCEPT_CHARSET => "utf-8",
33
33
  USER_AGENT => user_agent,
34
- CONTENT_TYPE => 'application/x-www-form-urlencoded'
34
+ CONTENT_TYPE => 'application/json'
35
35
  },
36
36
  :ssl => { :verify => false },
37
37
  :url => options.fetch(:endpoint) { Github.endpoint }
38
38
  }.merge(options)
39
39
  end
40
40
 
41
+ # Default middleware stack that uses default adapter as specified at
42
+ # configuration stage.
43
+ #
44
+ def default_middleware(options={})
45
+ Proc.new do |builder|
46
+ builder.use Github::Request::Jsonize
47
+ builder.use Faraday::Request::Multipart
48
+ builder.use Faraday::Request::UrlEncoded
49
+ builder.use Github::Request::OAuth2, oauth_token if oauth_token?
50
+ builder.use Github::Request::BasicAuth, authentication if basic_authed?
51
+
52
+ builder.use Faraday::Response::Logger if ENV['DEBUG']
53
+ builder.use Github::Response::Helpers
54
+ unless options[:raw]
55
+ builder.use Github::Response::Mashify
56
+ builder.use Github::Response::Jsonize
57
+ end
58
+ builder.use Github::Response::RaiseError
59
+ builder.adapter adapter
60
+ end
61
+ end
62
+
41
63
  @connection = nil
42
64
 
43
- def clear_cache # :nodoc:
65
+ @stack = nil
66
+
67
+ def clear_cache
44
68
  @connection = nil
45
69
  end
46
70
 
47
- def caching? # :nodoc:
71
+ def caching?
48
72
  !@connection.nil?
49
73
  end
50
74
 
51
- def connection(options = {}) # :nodoc:
75
+ # Exposes middleware builder to facilitate custom stacks and easy
76
+ # addition of new extensions such as cache adapter.
77
+ #
78
+ def stack(options={}, &block)
79
+ @stack ||= begin
80
+ if block_given?
81
+ Faraday::Builder.new(&block)
82
+ else
83
+ Faraday::Builder.new(&default_middleware(options))
84
+ end
85
+ end
86
+ end
52
87
 
88
+ # Returns a Fraday::Connection object
89
+ #
90
+ def connection(options = {})
53
91
  conn_options = default_options(options)
54
92
  clear_cache unless options.empty?
93
+ puts "OPTIONS:#{conn_options.inspect}" if ENV['DEBUG']
55
94
 
56
- @connection ||= begin
57
- Faraday.new(conn_options) do |builder|
58
- puts "OPTIONS:#{conn_options.inspect}" if ENV['DEBUG']
59
-
60
- builder.use Github::Request::Jsonize
61
- builder.use Faraday::Request::Multipart
62
- builder.use Faraday::Request::UrlEncoded
63
- builder.use Faraday::Response::Logger if ENV['DEBUG']
64
-
65
- builder.use Github::Request::OAuth2, oauth_token if oauth_token?
66
- builder.use Github::Request::BasicAuth, authentication if basic_authed?
67
-
68
- builder.use Github::Response::Helpers
69
- unless options[:raw]
70
- builder.use Github::Response::Mashify
71
- builder.use Github::Response::Jsonize
72
- end
73
-
74
- builder.use Github::Response::RaiseError
75
- builder.adapter adapter
76
- end
77
- end
95
+ @connection ||= Faraday.new(conn_options.merge(:builder => stack(options)))
78
96
  end
79
97
 
80
98
  end # Connection
@@ -4,7 +4,7 @@ module Github
4
4
  module VERSION
5
5
  MAJOR = 0
6
6
  MINOR = 6
7
- PATCH = 2
7
+ PATCH = 3
8
8
  BUILD = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.');
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.6.2
4
+ version: 0.6.3
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: 2012-07-15 00:00:00.000000000Z
12
+ date: 2012-07-17 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashie
16
- requirement: &2153389620 !ruby/object:Gem::Requirement
16
+ requirement: &2153056440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153389620
24
+ version_requirements: *2153056440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: faraday
27
- requirement: &2153389100 !ruby/object:Gem::Requirement
27
+ requirement: &2153055720 !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: *2153389100
35
+ version_requirements: *2153055720
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: multi_json
38
- requirement: &2153388580 !ruby/object:Gem::Requirement
38
+ requirement: &2153055000 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '1.3'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2153388580
46
+ version_requirements: *2153055000
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: oauth2
49
- requirement: &2153388020 !ruby/object:Gem::Requirement
49
+ requirement: &2153054440 !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: *2153388020
57
+ version_requirements: *2153054440
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: nokogiri
60
- requirement: &2153387460 !ruby/object:Gem::Requirement
60
+ requirement: &2153053580 !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: *2153387460
68
+ version_requirements: *2153053580
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &2153386960 !ruby/object:Gem::Requirement
71
+ requirement: &2153053000 !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: *2153386960
79
+ version_requirements: *2153053000
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: cucumber
82
- requirement: &2153386480 !ruby/object:Gem::Requirement
82
+ requirement: &2153052540 !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: *2153386480
90
+ version_requirements: *2153052540
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: webmock
93
- requirement: &2153386000 !ruby/object:Gem::Requirement
93
+ requirement: &2153052080 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 1.8.0
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2153386000
101
+ version_requirements: *2153052080
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: vcr
104
- requirement: &2153385500 !ruby/object:Gem::Requirement
104
+ requirement: &2153051600 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 2.2.0
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *2153385500
112
+ version_requirements: *2153051600
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: simplecov
115
- requirement: &2153385020 !ruby/object:Gem::Requirement
115
+ requirement: &2153051140 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 0.6.1
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *2153385020
123
+ version_requirements: *2153051140
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: guard
126
- requirement: &2153384580 !ruby/object:Gem::Requirement
126
+ requirement: &2153050760 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *2153384580
134
+ version_requirements: *2153050760
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: guard-rspec
137
- requirement: &2153384040 !ruby/object:Gem::Requirement
137
+ requirement: &2153050300 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *2153384040
145
+ version_requirements: *2153050300
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: guard-cucumber
148
- requirement: &2153383600 !ruby/object:Gem::Requirement
148
+ requirement: &2153049880 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,10 +153,10 @@ dependencies:
153
153
  version: '0'
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *2153383600
156
+ version_requirements: *2153049880
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: rake
159
- requirement: &2153383160 !ruby/object:Gem::Requirement
159
+ requirement: &2153049460 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ! '>='
@@ -164,10 +164,10 @@ dependencies:
164
164
  version: '0'
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *2153383160
167
+ version_requirements: *2153049460
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: bundler
170
- requirement: &2153382720 !ruby/object:Gem::Requirement
170
+ requirement: &2153049040 !ruby/object:Gem::Requirement
171
171
  none: false
172
172
  requirements:
173
173
  - - ! '>='
@@ -175,7 +175,7 @@ dependencies:
175
175
  version: '0'
176
176
  type: :development
177
177
  prerelease: false
178
- version_requirements: *2153382720
178
+ version_requirements: *2153049040
179
179
  description: ! ' Ruby wrapper that supports all of the GitHub API v3 methods(nearly
180
180
  200). It''s build in a modular way, that is, you can either instantiate the whole
181
181
  api wrapper Github.new or use parts of it e.i. Github::Repos.new if working solely
@@ -525,7 +525,7 @@ files:
525
525
  homepage: https://github.com/peter-murach/github
526
526
  licenses: []
527
527
  post_install_message: ! "\n--------------------------------------------------------------------------------\nThank
528
- you for installing github_api-0.6.2.\n\n*NOTE*: Version 0.5.0 introduces breaking
528
+ you for installing github_api-0.6.3.\n\n*NOTE*: Version 0.5.0 introduces breaking
529
529
  changes to the way github api is queried.\nThe interface has been rewritten to be
530
530
  more consistent with REST verbs that\ninteract with GitHub hypermedia resources.
531
531
  Thus, to list resources 'list' or 'all'\nverbs are used, to retrieve individual