weary 0.7.2 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/.gitignore +4 -1
  2. data/.rspec +2 -0
  3. data/.travis.yml +10 -0
  4. data/Gemfile +11 -8
  5. data/Gemfile.lock +49 -53
  6. data/LICENSE +1 -1
  7. data/README.md +134 -208
  8. data/Rakefile +6 -47
  9. data/lib/weary.rb +4 -66
  10. data/lib/weary/adapter.rb +23 -0
  11. data/lib/weary/adapters/net_http.rb +68 -0
  12. data/lib/weary/client.rb +243 -0
  13. data/lib/weary/deferred.rb +35 -0
  14. data/lib/weary/env.rb +32 -0
  15. data/lib/weary/middleware.rb +9 -0
  16. data/lib/weary/middleware/basic_auth.rb +17 -0
  17. data/lib/weary/middleware/content_type.rb +28 -0
  18. data/lib/weary/middleware/oauth.rb +31 -0
  19. data/lib/weary/request.rb +137 -124
  20. data/lib/weary/resource.rb +152 -128
  21. data/lib/weary/response.rb +48 -99
  22. data/lib/weary/route.rb +53 -0
  23. data/lib/weary/version.rb +3 -0
  24. data/spec/spec_helper.rb +4 -56
  25. data/spec/support/shared_examples_for_a_rack_app.rb +70 -0
  26. data/spec/support/shared_examples_for_a_rack_env.rb +14 -0
  27. data/spec/support/shared_examples_for_a_uri.rb +9 -0
  28. data/spec/weary/adapter_spec.rb +26 -0
  29. data/spec/weary/adapters/nethttp_spec.rb +88 -0
  30. data/spec/weary/client_spec.rb +258 -0
  31. data/spec/weary/deferred_spec.rb +35 -0
  32. data/spec/weary/env_spec.rb +12 -0
  33. data/spec/weary/middleware/basic_auth_spec.rb +23 -0
  34. data/spec/weary/middleware/content_type_spec.rb +34 -0
  35. data/spec/weary/middleware/oauth_spec.rb +27 -0
  36. data/spec/weary/request_spec.rb +227 -315
  37. data/spec/weary/resource_spec.rb +233 -233
  38. data/spec/weary/response_spec.rb +82 -159
  39. data/spec/weary/route_spec.rb +72 -0
  40. data/spec/weary_spec.rb +3 -56
  41. data/weary.gemspec +16 -79
  42. metadata +138 -98
  43. data/VERSION +0 -1
  44. data/examples/batch.rb +0 -20
  45. data/examples/repo.rb +0 -16
  46. data/examples/status.rb +0 -26
  47. data/lib/weary/base.rb +0 -124
  48. data/lib/weary/batch.rb +0 -37
  49. data/lib/weary/exceptions.rb +0 -15
  50. data/lib/weary/httpverb.rb +0 -32
  51. data/spec/fixtures/github.yml +0 -11
  52. data/spec/fixtures/twitter.xml +0 -763
  53. data/spec/fixtures/vimeo.json +0 -1
  54. data/spec/weary/base_spec.rb +0 -320
  55. data/spec/weary/batch_spec.rb +0 -71
  56. data/spec/weary/httpverb_spec.rb +0 -25
metadata CHANGED
@@ -1,143 +1,183 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: weary
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 7
8
- - 2
9
- version: 0.7.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.rc1
5
+ prerelease: 6
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Mark Wunsch
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-03-08 00:00:00 -05:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: crack
12
+ date: 2012-03-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
16
+ requirement: &70096837531960 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.4.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70096837531960
25
+ - !ruby/object:Gem::Dependency
26
+ name: addressable
27
+ requirement: &70096837531380 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.2.6
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70096837531380
36
+ - !ruby/object:Gem::Dependency
37
+ name: promise
38
+ requirement: &70096837530880 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.3.0
44
+ type: :runtime
22
45
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- - 1
30
- - 7
31
- version: 0.1.7
46
+ version_requirements: *70096837530880
47
+ - !ruby/object:Gem::Dependency
48
+ name: simple_oauth
49
+ requirement: &70096837530400 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.5
32
55
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: oauth
36
56
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
- - 3
44
- - 5
45
- version: 0.3.5
57
+ version_requirements: *70096837530400
58
+ - !ruby/object:Gem::Dependency
59
+ name: multi_json
60
+ requirement: &70096837529860 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.1.0
46
66
  type: :runtime
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: bundler
50
67
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- segments:
56
- - 0
57
- - 9
58
- - 7
59
- version: 0.9.7
68
+ version_requirements: *70096837529860
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: &70096837529320 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 2.8.0
60
77
  type: :development
61
- version_requirements: *id003
62
- description: A tiny DSL that makes the consumption of RESTful web services simple.
78
+ prerelease: false
79
+ version_requirements: *70096837529320
80
+ - !ruby/object:Gem::Dependency
81
+ name: webmock
82
+ requirement: &70096837528800 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 1.7.10
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70096837528800
91
+ description: ! 'A framework and DSL to Ruby clients to RESTful web services. '
63
92
  email: mark@markwunsch.com
64
93
  executables: []
65
-
66
94
  extensions: []
67
-
68
- extra_rdoc_files:
69
- - LICENSE
70
- - README.md
71
- files:
95
+ extra_rdoc_files: []
96
+ files:
72
97
  - .gitignore
98
+ - .rspec
99
+ - .travis.yml
73
100
  - Gemfile
74
101
  - Gemfile.lock
75
102
  - LICENSE
76
103
  - README.md
77
104
  - Rakefile
78
- - VERSION
79
- - examples/batch.rb
80
- - examples/repo.rb
81
- - examples/status.rb
82
105
  - lib/weary.rb
83
- - lib/weary/base.rb
84
- - lib/weary/batch.rb
85
- - lib/weary/exceptions.rb
86
- - lib/weary/httpverb.rb
106
+ - lib/weary/adapter.rb
107
+ - lib/weary/adapters/net_http.rb
108
+ - lib/weary/client.rb
109
+ - lib/weary/deferred.rb
110
+ - lib/weary/env.rb
111
+ - lib/weary/middleware.rb
112
+ - lib/weary/middleware/basic_auth.rb
113
+ - lib/weary/middleware/content_type.rb
114
+ - lib/weary/middleware/oauth.rb
87
115
  - lib/weary/request.rb
88
116
  - lib/weary/resource.rb
89
117
  - lib/weary/response.rb
90
- - spec/fixtures/github.yml
91
- - spec/fixtures/twitter.xml
92
- - spec/fixtures/vimeo.json
118
+ - lib/weary/route.rb
119
+ - lib/weary/version.rb
93
120
  - spec/spec_helper.rb
94
- - spec/weary/base_spec.rb
95
- - spec/weary/batch_spec.rb
96
- - spec/weary/httpverb_spec.rb
121
+ - spec/support/shared_examples_for_a_rack_app.rb
122
+ - spec/support/shared_examples_for_a_rack_env.rb
123
+ - spec/support/shared_examples_for_a_uri.rb
124
+ - spec/weary/adapter_spec.rb
125
+ - spec/weary/adapters/nethttp_spec.rb
126
+ - spec/weary/client_spec.rb
127
+ - spec/weary/deferred_spec.rb
128
+ - spec/weary/env_spec.rb
129
+ - spec/weary/middleware/basic_auth_spec.rb
130
+ - spec/weary/middleware/content_type_spec.rb
131
+ - spec/weary/middleware/oauth_spec.rb
97
132
  - spec/weary/request_spec.rb
98
133
  - spec/weary/resource_spec.rb
99
134
  - spec/weary/response_spec.rb
135
+ - spec/weary/route_spec.rb
100
136
  - spec/weary_spec.rb
101
137
  - weary.gemspec
102
- has_rdoc: true
103
138
  homepage: http://github.com/mwunsch/weary
104
139
  licenses: []
105
-
106
140
  post_install_message:
107
- rdoc_options:
108
- - --charset=UTF-8
109
- require_paths:
141
+ rdoc_options: []
142
+ require_paths:
110
143
  - lib
111
- required_ruby_version: !ruby/object:Gem::Requirement
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- segments:
116
- - 0
117
- version: "0"
118
- required_rubygems_version: !ruby/object:Gem::Requirement
119
- requirements:
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- segments:
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ segments:
123
151
  - 0
124
- version: "0"
152
+ hash: 3096398000685977380
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>'
157
+ - !ruby/object:Gem::Version
158
+ version: 1.3.1
125
159
  requirements: []
126
-
127
160
  rubyforge_project: weary
128
- rubygems_version: 1.3.6
161
+ rubygems_version: 1.8.11
129
162
  signing_key:
130
163
  specification_version: 3
131
- summary: A little DSL for consuming RESTful web services
132
- test_files:
164
+ summary: A framework and DSL for the consumption of RESTful web services.
165
+ test_files:
133
166
  - spec/spec_helper.rb
134
- - spec/weary/base_spec.rb
135
- - spec/weary/batch_spec.rb
136
- - spec/weary/httpverb_spec.rb
167
+ - spec/support/shared_examples_for_a_rack_app.rb
168
+ - spec/support/shared_examples_for_a_rack_env.rb
169
+ - spec/support/shared_examples_for_a_uri.rb
170
+ - spec/weary/adapter_spec.rb
171
+ - spec/weary/adapters/nethttp_spec.rb
172
+ - spec/weary/client_spec.rb
173
+ - spec/weary/deferred_spec.rb
174
+ - spec/weary/env_spec.rb
175
+ - spec/weary/middleware/basic_auth_spec.rb
176
+ - spec/weary/middleware/content_type_spec.rb
177
+ - spec/weary/middleware/oauth_spec.rb
137
178
  - spec/weary/request_spec.rb
138
179
  - spec/weary/resource_spec.rb
139
180
  - spec/weary/response_spec.rb
181
+ - spec/weary/route_spec.rb
140
182
  - spec/weary_spec.rb
141
- - examples/batch.rb
142
- - examples/repo.rb
143
- - examples/status.rb
183
+ has_rdoc:
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.7.2
data/examples/batch.rb DELETED
@@ -1,20 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- require 'rubygems'
3
- require 'weary'
4
- require 'fakeweb'
5
- require 'pp'
6
-
7
- hello = "Hello from"
8
- resources = %w[http://twitter.com http://github.com http://vimeo.com http://tumblr.com]
9
- resources.each {|url| FakeWeb.register_uri :get, url, :body => "#{hello} #{url}" }
10
-
11
- requests = []
12
- resources.each do |url|
13
- requests << Weary.get(url) do |request|
14
- request.on_complete { |response| puts response.body }
15
- end
16
- end
17
-
18
- Weary.batch(requests).perform
19
-
20
- FakeWeb.clean_registry
data/examples/repo.rb DELETED
@@ -1,16 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- require 'rubygems'
3
- require 'weary'
4
-
5
- class Repository
6
-
7
- def show(user, repo)
8
- Weary.get "http://github.com/api/v2/yaml/repos/show/#{user}/#{repo}"
9
- end
10
-
11
- end
12
-
13
- weary = Repository.new
14
- weary.show('mwunsch','weary').perform do |response|
15
- puts response.body
16
- end
data/examples/status.rb DELETED
@@ -1,26 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- require 'rubygems'
3
- require 'weary'
4
- require 'pp'
5
-
6
- class Status < Weary::Base
7
-
8
- domain "http://twitter.com/statuses/"
9
-
10
- get "user_timeline" do |resource|
11
- resource.requires = [:id]
12
- resource.with = [:user_id, :screen_name, :since_id, :max_id, :count, :page]
13
- end
14
-
15
- end
16
-
17
- toots = Status.new
18
-
19
- toots.user_timeline(:id => "markwunsch").perform do |response|
20
- if response.success?
21
- recent_toot = response[0]
22
- puts "@#{recent_toot['user']['screen_name']}: \"#{recent_toot['text']}\""
23
- else
24
- puts "#{response.code}: #{response.message}"
25
- end
26
- end
data/lib/weary/base.rb DELETED
@@ -1,124 +0,0 @@
1
- module Weary
2
- class Base
3
- @@resources = {}
4
-
5
- attr_accessor :defaults
6
-
7
- # Assign credentials to be used when authenticating to a Resource.
8
- # Can be a username/password combo, or an OAuth::AccessToken
9
- def credentials(username,password='')
10
- if username.is_a?(OAuth::AccessToken)
11
- @credentials = username
12
- else
13
- @credentials = {:username => username, :password => password}
14
- end
15
- end
16
-
17
- # Each Weary::Base object has its own set of Resources
18
- def resources
19
- @resources ||= Marshal.load(Marshal.dump(@@resources))
20
- end
21
-
22
- # Make changes to a Resource given and rebuild the Request method for this object
23
- def modify_resource(name)
24
- yield resources[name] if block_given?
25
- rebuild_method(resources[name])
26
- end
27
-
28
- # Rebuild the Request Method for a given Resource. This only affects the current instance.
29
- def rebuild_method(resource)
30
- instance_eval %Q{
31
- def #{resource.name}(params={})
32
- resources[:#{resource.name}].build!(params, @defaults, @credentials)
33
- end
34
- }
35
- end
36
-
37
- class << self
38
- # Getter for class-level resources
39
- def resources
40
- @@resources
41
- end
42
-
43
- # Declare a resource. Use it with a block to setup the resource
44
- #
45
- # Methods that are understood are:
46
- # [<tt>via</tt>] Get, Post, etc. Defaults to a GET request
47
- # [<tt>with</tt>] An array of parameters that will be passed to the body or query of the request. If you pass a hash, it will define default <tt>values</tt> for params <tt>keys</tt>
48
- # [<tt>requires</tt>] Array of members of <tt>:with</tt> that are required by the resource.
49
- # [<tt>authenticates</tt>] Boolean value; does the resource require authentication?
50
- # [<tt>url</tt>] The url of the resource.
51
- # [<tt>follows</tt>] Boolean; Does this follow redirects? Defaults to true
52
- # [<tt>headers</tt>] Set headers for the HTTP Request
53
- def get(name,&block)
54
- build_resource(name, :get, &block)
55
- end
56
- alias declare get
57
-
58
- # Declares a Resource to be requested via POST
59
- def post(name,&block)
60
- build_resource(name, :post, &block)
61
- end
62
-
63
- # Declares a Resource to be requested via PUT
64
- def put(name,&block)
65
- build_resource(name, :put, &block)
66
- end
67
-
68
- # Declares a Resource to be requested via DELETE
69
- def delete(name,&block)
70
- build_resource(name, :delete, &block)
71
- end
72
-
73
- # Set custom default Headers for your Request
74
- def headers(headers)
75
- @headers = headers
76
- end
77
-
78
- # Sets the domain to be used to build default url's
79
- def domain(dom)
80
- domain = URI.extract(dom)
81
- raise ArgumentError, 'The domain must be a URL.' if domain.blank?
82
- @domain = URI.parse(domain[0]).normalize.to_s
83
- end
84
-
85
- # Sets a default format, used to build default Resource url's
86
- def format(format)
87
- @format = format
88
- end
89
-
90
- # Prepare and store the Resource
91
- def build_resource(name,verb,&block)
92
- resource = prepare_resource(name,verb)
93
- yield resource if block_given?
94
- store_resource(resource)
95
- build_method(resource)
96
- resource
97
- end
98
-
99
- # Prepare a Resource with set defaults
100
- def prepare_resource(name,via = :get)
101
- preparation = Weary::Resource.new(name)
102
- preparation.via = via
103
- preparation.headers = @headers unless @headers.blank?
104
- preparation.url = "#{@domain}#{preparation.name}." + (@format || :json).to_s if @domain
105
- preparation
106
- end
107
-
108
- # Store the resource for future use
109
- def store_resource(resource)
110
- @@resources[resource.name.to_sym] = resource
111
- resource
112
- end
113
-
114
- # Build a method to form a Request for the given Resource
115
- def build_method(resource)
116
- define_method resource.name.to_sym do |*args|
117
- args.blank? ? params = {} : params = args[0]
118
- resource.build!(params, @defaults, @credentials)
119
- end
120
- end
121
-
122
- end
123
- end
124
- end