pluct 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGE3ZGE4ZDUxYWIwYzAyNTQzN2I0MzNiZGEyYTBiZDk5OTRiNGEyNA==
4
+ ODUzYWFiYmEwMTZkNGY1ZTMxZDk5ZGZjYTI5MjAzMjJkYzU5YmRkOQ==
5
5
  data.tar.gz: !binary |-
6
- MGY5YWYxYzk4NjAyNTM5ZGQ3YjBjZDNjNWY4YjZmZjMwYTlhMmYxZQ==
6
+ YjgwZmRiZjdjMzZiMjhiZjhkMTEwOWQ0ZjM5Yjk2MmVmOGUzOWZlZg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YTMyYzlkZWFlNWU3Mjc2NDcyMDI2MzFiMTljZGM5MjliZWVhYTk5N2ExYjJl
10
- ZjJlNTk5YmFiYTEwYzdlZTZiOGY2OGZjYmJmZTM1NGNmZGFlZTJhMDQzZTA1
11
- MDc5OTU4ZjljNjc3NGU0Y2NjM2I0NWIyYzkzMWI5NTYyNmJmYTM=
9
+ M2I2YTc0Y2Y0M2FkOWFiYWFiYWRjYzU0ZGZjNDc3YjlhMDZmNGUxYWM2Yzc0
10
+ MTY3MzI5YWM0Yzg3NDgyYWUxNTFlNjk2OGY4MzYxNjM2MjU3YjQxNjRjMTU0
11
+ MmFiMTE5ZTlhMTExM2E5Y2JjYmU5MWIyMzBhOTBkYmNjMTJlY2U=
12
12
  data.tar.gz: !binary |-
13
- ZWYwMjE2YmU0NDQzMTc1ODNhOGI5Zjc3NDBlMWQzMDNhZmExOGQ0NTEzMjMw
14
- OGQ2ODc5YjYyYTc4NWQwMjhiYTQwNDVjYjFjMjRiNTM2NmQ2YWZlZWJlNDYy
15
- OWRlZWVlOGUwMzQxM2E5MTg2YWI0NzJmYzAwYTBjNzMwZWQzN2U=
13
+ ODYxMWY4NzQ4OTFkNDFkZDQ3NDk2ZjQ2YzdkNTNkNWI4OTcxNTNjZTQxYzg5
14
+ NTY4OTEyODk4ZWQ1ZDIyNGUzMmY3ZTcyZThmMjljZGU2MTM1MmQyYjUwYjBi
15
+ ODcxMWE0NDZjODhjNGRiOTBmNzY1ZDUxMWJjZTJhYzM5OTcwZmE=
@@ -50,7 +50,7 @@ module Pluct
50
50
  options = Hash[*opts] if options
51
51
  resource = RestClient::Resource.new(url)
52
52
  options = (options ? DEFAULT_HEADERS.merge(options) : DEFAULT_HEADERS)
53
- resource.put(data, options)
53
+ resource.put(data.to_json, options)
54
54
  rescue RestClient::Exception => e
55
55
  raise_exception(e)
56
56
  end
@@ -60,7 +60,7 @@ module Pluct
60
60
  options = Hash[*opts] if options
61
61
  resource = RestClient::Resource.new(url)
62
62
  options = (options ? DEFAULT_HEADERS.merge(options) : DEFAULT_HEADERS)
63
- resource.patch(data, options)
63
+ resource.patch(data.to_json, options)
64
64
  rescue RestClient::Exception => e
65
65
  raise_exception(e)
66
66
  end
@@ -20,8 +20,17 @@ module Pluct
20
20
  def self.create_methods(links=[])
21
21
  links.each do |link|
22
22
  define_method link.rel do |*args|
23
+ query_string, *options = *args
23
24
  method = link["method"] || "GET"
24
- send(method.downcase, link.href, *args)
25
+ href = link["href"]
26
+
27
+ if query_string
28
+ href = Addressable::Template.new(href)
29
+ href = href.expand(query_string).to_s
30
+ end
31
+
32
+ #query_string (uri_template), payload, headers
33
+ send(method.downcase, href, *options)
25
34
  end
26
35
  end
27
36
  end
data/lib/pluct/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pluct
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/pluct.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'addressable/template'
1
2
  require 'pluct/version'
2
3
  require 'multi_json'
3
4
  require 'pluct/extensions/hash'
data/pluct.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["albertonb@gmail.com"]
11
11
  spec.description = %q{json-schema hypermedia client}
12
12
  spec.summary = %q{json-schema hypermedia client}
13
- spec.homepage = "http://github.com/globocom/pluct"
13
+ spec.homepage = "http://github.com/globocom/pluct-ruby"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_development_dependency "addressable"
21
22
  spec.add_development_dependency "bundler", "~> 1.3"
22
23
  spec.add_development_dependency "hashie"
23
24
  spec.add_development_dependency "multi_json"
@@ -26,6 +27,7 @@ Gem::Specification.new do |spec|
26
27
  spec.add_development_dependency "rspec"
27
28
  spec.add_development_dependency "vcr"
28
29
  spec.add_development_dependency "webmock"
30
+
29
31
 
30
32
  spec.add_development_dependency "pry"
31
33
  spec.add_development_dependency "pry-nav"
@@ -9,4 +9,12 @@ describe Pluct, :acceptance do
9
9
  expect(resource_self).to have_key("items")
10
10
  expect(resource_self.item_count).to eq 2
11
11
  end
12
- end
12
+
13
+ it 'creates a new app', :vcr, cassette_name: 'acceptance/creates_new_app' do
14
+ resource = Pluct.get_resource 'http://localhost:8888/baas/apps'
15
+ response = resource.create(nil, {name: 'New App', description: 'My Awesome App'})
16
+
17
+ expect(response.code).to eq 201
18
+ expect(response.headers[:location]).to_not be_nil
19
+ end
20
+ end
@@ -0,0 +1,187 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:8888/baas/apps
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Content-Length:
24
+ - '1129'
25
+ Server:
26
+ - TornadoServer/2.4.1
27
+ Etag:
28
+ - ! '"eb6a3361d671dd8cf334bdae7c539d16359583af"'
29
+ Link:
30
+ - <http://localhost:8888/baas/schemas/app-collection>; rel=describedby
31
+ Cache-Control:
32
+ - max-age=0
33
+ Access-Control-Allow-Origin:
34
+ - ! '*'
35
+ Content-Type:
36
+ - application/json; charset=UTF-8; profile=http://localhost:8888/baas/schemas/app-collection
37
+ body:
38
+ encoding: US-ASCII
39
+ string: ! '{"items": [{"description": "Awesome Data, bro!", "name": "My Awesome
40
+ App", "resource_id": "4bc4e297ec43467eabe04c82a505ae24"}, {"description":
41
+ "Awesome Data, bro!", "name": "My Awesome App", "resource_id": "84748678085f42c1bc4282e309de37d8"},
42
+ {"description": "s", "name": "asds", "resource_id": "5c7c8df86c074d08a5e0cab8e57a6b81"},
43
+ {"description": "My Awesome App", "name": "New App", "resource_id": "dd68e019f6ab48cbb48d995d276b6113"},
44
+ {"description": "My Awesome App", "name": "New App", "resource_id": "ee85cecf98a44d7f928d523e1e3898ea"}],
45
+ "links": [{"href": "http://localhost:8888/baas/apps/{resource_id}", "rel":
46
+ "item"}, {"href": "http://localhost:8888/baas/apps/{resource_id}", "method":
47
+ "PATCH", "rel": "edit"}, {"href": "http://localhost:8888/baas/apps/{resource_id}",
48
+ "method": "PUT", "rel": "replace"}, {"href": "http://localhost:8888/baas/apps/{resource_id}",
49
+ "method": "DELETE", "rel": "delete"}, {"href": "http://localhost:8888/baas/apps",
50
+ "rel": "self"}, {"href": "http://localhost:8888/baas/apps", "method": "POST",
51
+ "rel": "create", "schema": {"$ref": "http://localhost:8888/baas/schemas/app"}}],
52
+ "item_count": 5}'
53
+ http_version:
54
+ recorded_at: Sat, 22 Jun 2013 16:09:21 GMT
55
+ - request:
56
+ method: get
57
+ uri: http://localhost:8888/baas/schemas/app-collection
58
+ body:
59
+ encoding: US-ASCII
60
+ string: ''
61
+ headers:
62
+ Accept:
63
+ - ! '*/*; q=0.5, application/xml'
64
+ Accept-Encoding:
65
+ - gzip, deflate
66
+ Content-Type:
67
+ - application/json
68
+ User-Agent:
69
+ - Ruby
70
+ response:
71
+ status:
72
+ code: 200
73
+ message: OK
74
+ headers:
75
+ Content-Length:
76
+ - '367'
77
+ Server:
78
+ - TornadoServer/2.4.1
79
+ Etag:
80
+ - ! '"5a1c821d55fe0e75bb01048c47e50c077bd9d5c3"'
81
+ Cache-Control:
82
+ - max-age=0
83
+ Access-Control-Allow-Origin:
84
+ - ! '*'
85
+ Content-Type:
86
+ - application/json; charset=UTF-8
87
+ body:
88
+ encoding: US-ASCII
89
+ string: ! '{"links": [{"href": "http://localhost:8888/baas/apps", "rel": "self"},
90
+ {"href": "http://localhost:8888/baas/apps", "method": "POST", "rel": "create",
91
+ "schema": {"$ref": "http://localhost:8888/baas/schemas/app"}}, {"href": "http://localhost:8888/baas/apps?page={prev_page}",
92
+ "rel": "prev"}, {"href": "http://localhost:8888/baas/apps?page={next_page}",
93
+ "rel": "next"}]}'
94
+ http_version:
95
+ recorded_at: Sat, 22 Jun 2013 16:09:21 GMT
96
+ - request:
97
+ method: get
98
+ uri: http://localhost:8888/baas/apps
99
+ body:
100
+ encoding: US-ASCII
101
+ string: ''
102
+ headers:
103
+ Accept:
104
+ - ! '*/*; q=0.5, application/xml'
105
+ Accept-Encoding:
106
+ - gzip, deflate
107
+ Content-Type:
108
+ - application/json
109
+ User-Agent:
110
+ - Ruby
111
+ response:
112
+ status:
113
+ code: 200
114
+ message: OK
115
+ headers:
116
+ Content-Length:
117
+ - '1129'
118
+ Server:
119
+ - TornadoServer/2.4.1
120
+ Etag:
121
+ - ! '"eb6a3361d671dd8cf334bdae7c539d16359583af"'
122
+ Link:
123
+ - <http://localhost:8888/baas/schemas/app-collection>; rel=describedby
124
+ Cache-Control:
125
+ - max-age=0
126
+ Access-Control-Allow-Origin:
127
+ - ! '*'
128
+ Content-Type:
129
+ - application/json; charset=UTF-8; profile=http://localhost:8888/baas/schemas/app-collection
130
+ body:
131
+ encoding: US-ASCII
132
+ string: ! '{"items": [{"description": "Awesome Data, bro!", "name": "My Awesome
133
+ App", "resource_id": "4bc4e297ec43467eabe04c82a505ae24"}, {"description":
134
+ "Awesome Data, bro!", "name": "My Awesome App", "resource_id": "84748678085f42c1bc4282e309de37d8"},
135
+ {"description": "s", "name": "asds", "resource_id": "5c7c8df86c074d08a5e0cab8e57a6b81"},
136
+ {"description": "My Awesome App", "name": "New App", "resource_id": "dd68e019f6ab48cbb48d995d276b6113"},
137
+ {"description": "My Awesome App", "name": "New App", "resource_id": "ee85cecf98a44d7f928d523e1e3898ea"}],
138
+ "links": [{"href": "http://localhost:8888/baas/apps/{resource_id}", "rel":
139
+ "item"}, {"href": "http://localhost:8888/baas/apps/{resource_id}", "method":
140
+ "PATCH", "rel": "edit"}, {"href": "http://localhost:8888/baas/apps/{resource_id}",
141
+ "method": "PUT", "rel": "replace"}, {"href": "http://localhost:8888/baas/apps/{resource_id}",
142
+ "method": "DELETE", "rel": "delete"}, {"href": "http://localhost:8888/baas/apps",
143
+ "rel": "self"}, {"href": "http://localhost:8888/baas/apps", "method": "POST",
144
+ "rel": "create", "schema": {"$ref": "http://localhost:8888/baas/schemas/app"}}],
145
+ "item_count": 5}'
146
+ http_version:
147
+ recorded_at: Sat, 22 Jun 2013 16:09:21 GMT
148
+ - request:
149
+ method: post
150
+ uri: http://localhost:8888/baas/apps
151
+ body:
152
+ encoding: UTF-8
153
+ string: ! '{"name":"New App","description":"My Awesome App"}'
154
+ headers:
155
+ Accept:
156
+ - ! '*/*; q=0.5, application/xml'
157
+ Accept-Encoding:
158
+ - gzip, deflate
159
+ Content-Type:
160
+ - application/json
161
+ Content-Length:
162
+ - '49'
163
+ User-Agent:
164
+ - Ruby
165
+ response:
166
+ status:
167
+ code: 201
168
+ message: Created
169
+ headers:
170
+ Content-Length:
171
+ - '0'
172
+ Server:
173
+ - TornadoServer/2.4.1
174
+ Location:
175
+ - http://localhost:8888/baas/apps/0d63bf8c52984744b6f3963740474299
176
+ Cache-Control:
177
+ - max-age=0
178
+ Access-Control-Allow-Origin:
179
+ - ! '*'
180
+ Content-Type:
181
+ - text/html; charset=UTF-8
182
+ body:
183
+ encoding: US-ASCII
184
+ string: ''
185
+ http_version:
186
+ recorded_at: Sat, 22 Jun 2013 16:09:21 GMT
187
+ recorded_with: VCR 2.5.0
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pluct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alberto Leal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-21 00:00:00.000000000 Z
11
+ date: 2013-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: addressable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -180,8 +194,9 @@ files:
180
194
  - spec/pluct/schema_spec.rb
181
195
  - spec/spec_helper.rb
182
196
  - spec/support/vcr.rb
197
+ - spec/support/vcr/acceptance/creates_new_app.yml
183
198
  - spec/support/vcr/acceptance/pluct_resource.yml
184
- homepage: http://github.com/globocom/pluct
199
+ homepage: http://github.com/globocom/pluct-ruby
185
200
  licenses:
186
201
  - MIT
187
202
  metadata: {}
@@ -214,5 +229,6 @@ test_files:
214
229
  - spec/pluct/schema_spec.rb
215
230
  - spec/spec_helper.rb
216
231
  - spec/support/vcr.rb
232
+ - spec/support/vcr/acceptance/creates_new_app.yml
217
233
  - spec/support/vcr/acceptance/pluct_resource.yml
218
234
  has_rdoc: