frenetic 0.0.11 → 0.0.12
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.
- data/README.md +1 -1
- data/lib/frenetic/resource.rb +7 -0
- data/lib/frenetic/version.rb +1 -1
- data/spec/lib/frenetic/resource_spec.rb +14 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -123,7 +123,7 @@ Or install it yourself as:
|
|
123
123
|
|
124
124
|
```ruby
|
125
125
|
MyAPI = Frenetic.new(
|
126
|
-
# 'adapter'
|
126
|
+
# 'adapter' => :patron # Or some other Faraday-compatible Adapter. Defaults to `:net_http`
|
127
127
|
'url' => 'https://api.yoursite.com',
|
128
128
|
'username' => 'yourname',
|
129
129
|
'password' => 'yourpassword',
|
data/lib/frenetic/resource.rb
CHANGED
@@ -19,6 +19,13 @@ class Frenetic
|
|
19
19
|
@_links
|
20
20
|
end
|
21
21
|
|
22
|
+
def attributes
|
23
|
+
self.class.schema.keys.each_with_object({}) do |key, attrs|
|
24
|
+
attrs[key] = public_send key
|
25
|
+
end
|
26
|
+
end
|
27
|
+
alias_method :to_hash, :attributes
|
28
|
+
|
22
29
|
# Attempts to retrieve the Resource Schema from the API based on the name
|
23
30
|
# of the subclass.
|
24
31
|
class << self
|
data/lib/frenetic/version.rb
CHANGED
@@ -9,7 +9,7 @@ describe Frenetic::Resource do
|
|
9
9
|
let(:description_stub) do
|
10
10
|
Frenetic::HalJson::ResponseWrapper.new('resources' => {
|
11
11
|
'schema' => {
|
12
|
-
'my_resource' => { 'properties' => { 'foo' => 'string' } },
|
12
|
+
'my_resource' => { 'properties' => { 'foo' => 'string', 'baz' => 'integer' } },
|
13
13
|
'my_other_resource' => { 'properties' => { 'bar' => 'integer' } }
|
14
14
|
} } )
|
15
15
|
end
|
@@ -25,6 +25,19 @@ describe Frenetic::Resource do
|
|
25
25
|
|
26
26
|
subject { resource }
|
27
27
|
|
28
|
+
describe '#attributes' do
|
29
|
+
subject { resource.attributes }
|
30
|
+
|
31
|
+
it { should include 'foo' => nil }
|
32
|
+
it { should include 'baz' => nil }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#to_hash' do
|
36
|
+
subject { resource.to_hash }
|
37
|
+
|
38
|
+
it { should == resource.attributes }
|
39
|
+
end
|
40
|
+
|
28
41
|
context "created from a Hash" do
|
29
42
|
let(:resource) { MyResource.new( foo: 'bar' ) }
|
30
43
|
|