grackle 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,22 @@
1
- == 0.2.0 (2012-6-10)
1
+ == 0.2.1 (2012-08-14)
2
+ * Add :valid_http_codes option that tells grackle not to raise an error when encountering those statuses.
3
+
4
+ == 0.2.0 (2012-06-10)
2
5
  * New auto_append_format attribute (thanks @jcsalterego) for specifying whether or not to automatically add .json, etc to a request URI
3
6
  * New response attribute which captures raw info about the response from the most recent request. This permits access to response headers with rate limit information. Thanks to @mandoescamilla.
4
7
  * Added Twitter's media upload endpoint. Thanks @jbrennon.
5
8
  * Modernized the code a bit with better test running and a new gemspec
6
9
  * Now testing in 1.8.6, 1.8.7, 1.9.2 and 1.9.3
7
10
 
8
- == 0.1.10 (2010-6-13)
11
+ == 0.1.10 (2010-06-13)
9
12
  * Changed :v1 (api.twitter.com/1) to be the default API instead of REST. :rest is now deprecated
10
13
  * Fixed issue with DELETE requests not being able to have form encoded body parameters. This was causing the list membership delete method to fail. As a side note, it appears that Twitter is actually violating the HTTP 1.1 spec on this one since RFC 2616 states that a DELETE "requests that the origin server delete the resource identified by the Request-URI" (note no mention of any "enclosed entity").
11
14
 
12
- == 0.1.9 (2010-2-28)
15
+ == 0.1.9 (2010-02-28)
13
16
  * Added support for a boolean option called auto_append_ids that controls whether parameters named "id" are automatically appended to the URL or used as request parameters. It's true by default so there's no change to existing behavior unless you explicitly set it to false.
14
17
  * Updated the README with changes describing how to use custom handlers (thanks akahn!)
15
18
 
16
- == 0.1.8 (2010-2-2)
19
+ == 0.1.8 (2010-02-02)
17
20
  * Added proxy support to Grackle::Transport via proxy attribute. Can specify a Proc that returns a Net::HTTP subclass or a Net::HTTP subclass directly. Typically this will be from Net::HTTP.Proxy.
18
21
 
19
22
  == 0.1.7 (2009-12-13)
@@ -79,7 +79,8 @@ module Grackle
79
79
  end
80
80
  end
81
81
 
82
- VALID_FORMATS = [:json,:xml,:atom,:rss]
82
+ VALID_FORMATS = [:json,:xml,:atom,:rss]
83
+ VALID_HTTP_CODES = [200]
83
84
 
84
85
  # Contains the mapping of API name symbols to actual host (and path)
85
86
  # prefixes to use with requests. You can add your own to this hash and
@@ -107,7 +108,7 @@ module Grackle
107
108
 
108
109
  attr_accessor :auth, :handlers, :default_format, :headers, :ssl, :api,
109
110
  :transport, :request, :api_hosts, :timeout, :auto_append_ids,
110
- :auto_append_format, :response_headers, :response
111
+ :auto_append_format, :response_headers, :response, :valid_http_codes
111
112
 
112
113
  # Arguments (all are optional):
113
114
  # - :username - Twitter username to authenticate with (deprecated in favor of :auth arg)
@@ -122,6 +123,7 @@ module Grackle
122
123
  # - :type=>:oauth - Include :consumer_key, :consumer_secret, :token and :token_secret keys
123
124
  # - :auto_append_format - true or false to include format in URI (e.g. /test.json). Default is true
124
125
  # - :response_headers - array of headers to return from the response
126
+ # - :valid_http_codes - array of HTTP codes to consider valid (non-error)
125
127
  def initialize(options={})
126
128
  self.transport = Transport.new
127
129
  self.handlers = {:json=>Handlers::JSONHandler.new,:xml=>Handlers::XMLHandler.new,:unknown=>Handlers::StringHandler.new}
@@ -135,7 +137,8 @@ module Grackle
135
137
  self.timeout = options[:timeout] || 60
136
138
  self.auto_append_ids = options[:auto_append_ids] == false ? false : true
137
139
  self.auth = {}
138
- self.response_headers = options[:response_headers] || DEFAULT_RESPONSE_HEADERS
140
+ self.response_headers = options[:response_headers] || DEFAULT_RESPONSE_HEADERS.clone
141
+ self.valid_http_codes = options[:valid_http_codes] || VALID_HTTP_CODES.clone
139
142
  if options.has_key?(:username) || options.has_key?(:password)
140
143
  #Use basic auth if :username and :password args are passed in
141
144
  self.auth.merge!({:type=>:basic,:username=>options[:username],:password=>options[:password]})
@@ -260,7 +263,7 @@ module Grackle
260
263
  def process_response(format,res)
261
264
  fmt_handler = handler(format)
262
265
  begin
263
- unless res.status == 200
266
+ unless self.valid_http_codes.include?(res.status)
264
267
  handle_error_response(res,fmt_handler)
265
268
  else
266
269
  fmt_handler.decode_response(res.body)
@@ -1,6 +1,6 @@
1
1
  module Grackle
2
2
 
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
 
5
5
  def self.version
6
6
  VERSION
@@ -381,7 +381,19 @@ class ClientTest < Test::Unit::TestCase
381
381
  assert_equal('/1/some_user/some_list/members.json',client.transport.url.path)
382
382
  assert_match(/user_id=12345/,Net::HTTP.request.body,"Parameters should be form encoded")
383
383
  end
384
-
384
+
385
+ def test_valid_http_codes_causes_error_not_to_raise
386
+ client = new_client(202,'{"id":12345,"screen_name":"test_user"}')
387
+ assert_raise(Grackle::TwitterError) do
388
+ value = client.users.show.json? :screen_name=>'test_user'
389
+ end
390
+
391
+ client = new_client(202,'{"id":12345,"screen_name":"test_user"}',:valid_http_codes=>[200,202])
392
+ assert_nothing_raised do
393
+ value = client.users.show.json? :screen_name=>'test_user'
394
+ end
395
+ end
396
+
385
397
  private
386
398
  def with_http_responder(responder)
387
399
  Net::HTTP.responder = responder
metadata CHANGED
@@ -1,75 +1,73 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: grackle
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Hayes Davis
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-06-10 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-08-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: json
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: mime-types
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mime-types
32
+ requirement: !ruby/object:Gem::Requirement
39
33
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
47
38
  type: :runtime
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: oauth
51
39
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: oauth
48
+ requirement: !ruby/object:Gem::Requirement
53
49
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
61
54
  type: :runtime
62
- version_requirements: *id003
63
- description: " Grackle is a library for the Twitter REST and Search API designed to not\n require a new release in the face Twitter API changes or errors.\n"
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ! " Grackle is a library for the Twitter REST and Search API designed
63
+ to not\n require a new release in the face Twitter API changes or errors.\n"
64
64
  email: hayes@unionmetrics.com
65
65
  executables: []
66
-
67
66
  extensions: []
68
-
69
- extra_rdoc_files:
67
+ extra_rdoc_files:
70
68
  - README.rdoc
71
69
  - CHANGELOG.rdoc
72
- files:
70
+ files:
73
71
  - README.rdoc
74
72
  - CHANGELOG.rdoc
75
73
  - lib/grackle/client.rb
@@ -81,39 +79,28 @@ files:
81
79
  - test/client_test.rb
82
80
  - test/handlers_test.rb
83
81
  - test/test_helper.rb
84
- has_rdoc: true
85
82
  homepage: http://github.com/hayesdavis/grackle
86
83
  licenses: []
87
-
88
84
  post_install_message:
89
85
  rdoc_options: []
90
-
91
- require_paths:
86
+ require_paths:
92
87
  - lib
93
- required_ruby_version: !ruby/object:Gem::Requirement
88
+ required_ruby_version: !ruby/object:Gem::Requirement
94
89
  none: false
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- hash: 3
99
- segments:
100
- - 0
101
- version: "0"
102
- required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
95
  none: false
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- hash: 3
108
- segments:
109
- - 0
110
- version: "0"
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
111
100
  requirements: []
112
-
113
101
  rubyforge_project:
114
- rubygems_version: 1.3.7
102
+ rubygems_version: 1.8.23
115
103
  signing_key:
116
104
  specification_version: 3
117
105
  summary: Grackle is a lightweight library for the Twitter REST and Search API.
118
106
  test_files: []
119
-