plaza 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +9 -1
- data/lib/plaza/models/restful_model.rb +3 -2
- data/lib/plaza/version.rb +1 -1
- data/spec/plaza/connection_spec.rb +0 -1
- data/spec/plaza/models/restful_model_spec.rb +8 -2
- data/spec/plaza/request_spec.rb +14 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b79e43959831ba5643a81a677979d6ea029b45a9
|
4
|
+
data.tar.gz: ddfeed268347f481f3ddf58ad2a6956b4c96b786
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1cc6173c0ba4b81dff74f0eac535cb6cad4399091f7631c6d7f50111005c6c962932efce29f6be96091d266cfbfce0bd0c90ad353cd0ed1b5b8f53cef00bb28
|
7
|
+
data.tar.gz: 3df71c1a00544708b80f80ff68f81f4f8a1aa3567b6e4881336b268c787c77733118d2b5f4c2a5398fe2896d900154f0ac833ce3038ec8cbef0f3de53e0291dd
|
data/README.md
CHANGED
@@ -116,7 +116,7 @@ Create models: `my_thing = Thing.create(:name => 'Bob')`. This results in an POS
|
|
116
116
|
Find existing models: `my_thing = Thing.find(10)`. This results in a GET API call like `GET
|
117
117
|
http://example.com/things/10`
|
118
118
|
|
119
|
-
Pass query string to API: `Thing.
|
119
|
+
Pass query string to API: `Thing.where(:name = 'bob')`. This results in an api call like `GET
|
120
120
|
http://example.com/rest/things?name=bob`. Returns an array.
|
121
121
|
|
122
122
|
Update model attributes: `my_thing.name = 'Kevin'`
|
@@ -147,6 +147,14 @@ fetch the related rest model.
|
|
147
147
|
Want to know more, go checkout the code, the guts of it are located at
|
148
148
|
`lib/plaza/models/restful_model.rb`
|
149
149
|
|
150
|
+
## Questions & Answers
|
151
|
+
|
152
|
+
**Q**. Why not ActiveResource?
|
153
|
+
|
154
|
+
**A**. ActiveResource is dependent on ActiveModel and ActiveSupport, both of which are tied to a
|
155
|
+
specific version of rails. We didn't want all the dependency. Building on top of Faraday and Virtus
|
156
|
+
offered greater flexibility, more awesome, and less dependencies.
|
157
|
+
|
150
158
|
## Contributing
|
151
159
|
|
152
160
|
1. Fork it ( https://github.com/[my-github-username]/plaza/fork )
|
@@ -48,7 +48,7 @@ module Plaza
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def plural_name
|
51
|
-
singular_name
|
51
|
+
Inflector.pluralize(singular_name)
|
52
52
|
end
|
53
53
|
|
54
54
|
def singular_name
|
@@ -144,7 +144,8 @@ module Plaza
|
|
144
144
|
if self.respond_to?(method_name + '_id')
|
145
145
|
obj_id = self.send(method_name + '_id')
|
146
146
|
class_name = Plaza::Inflector.classify(method_name)
|
147
|
-
|
147
|
+
klass = (self.class.name.split('::')[0..-2] + [class_name]).reduce(Module, :const_get)
|
148
|
+
return klass.find(obj_id)
|
148
149
|
else
|
149
150
|
raise NoMethodError.new "undefined method '#{method_name}' for #{self.class}"
|
150
151
|
end
|
data/lib/plaza/version.rb
CHANGED
@@ -16,7 +16,6 @@ describe Plaza::Connection do
|
|
16
16
|
'Accept'=>'application/json',
|
17
17
|
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
18
18
|
'Greetings'=>'HelloGoodbye',
|
19
|
-
'User-Agent'=>'Faraday v0.9.0',
|
20
19
|
'X-User-Id'=>''}
|
21
20
|
).to_return(:status => 200, :body => "", :headers => {})
|
22
21
|
connection = Plaza::Connection.for(:connection_spec)
|
@@ -19,7 +19,7 @@ module Foobar
|
|
19
19
|
plaza_config :foobar
|
20
20
|
|
21
21
|
has_many 'Foobar::Amajing'
|
22
|
-
attribute :
|
22
|
+
attribute :amajing_id, Integer
|
23
23
|
end
|
24
24
|
|
25
25
|
class Amajing
|
@@ -75,7 +75,7 @@ describe Thing do
|
|
75
75
|
{
|
76
76
|
'amabob' => {
|
77
77
|
'id' => 3,
|
78
|
-
'
|
78
|
+
'amajing_id' => 2
|
79
79
|
}
|
80
80
|
}
|
81
81
|
}
|
@@ -250,6 +250,12 @@ describe Thing do
|
|
250
250
|
stub_request(:get, 'http://example.com/rest/amajigs/2.json').to_return(body:amajig_hash.to_json)
|
251
251
|
thing.amajig.name.should == 'Jigger'
|
252
252
|
end
|
253
|
+
|
254
|
+
it 'should get reltated object in module' do
|
255
|
+
bob = Foobar::Amabob.new(amabob_hash['amabob'])
|
256
|
+
stub_request(:get, 'http://www.example.com/rest/amajings/2.json').to_return(body:amabobs_hash.to_json)
|
257
|
+
bob.amajing.class.name.should == 'Foobar::Amajing'
|
258
|
+
end
|
253
259
|
end
|
254
260
|
|
255
261
|
describe 'has_many relationships' do
|
data/spec/plaza/request_spec.rb
CHANGED
@@ -27,9 +27,7 @@ describe Request do
|
|
27
27
|
%i(get post put delete).each do |method|
|
28
28
|
it "##{method} should now add X-User-Id to headers" do
|
29
29
|
stub_request(method, "http://example.com/foobar").
|
30
|
-
with(:headers => {
|
31
|
-
'Accept'=>'application/json',
|
32
|
-
'User-Agent'=>'Faraday v0.9.0'}).
|
30
|
+
with(:headers => {'Accept'=>'application/json'}).
|
33
31
|
to_return(:status => 200, :body => "", :headers => {})
|
34
32
|
|
35
33
|
Request.new.send(method, '/foobar')
|
@@ -38,7 +36,19 @@ describe Request do
|
|
38
36
|
|
39
37
|
end
|
40
38
|
|
41
|
-
context "when
|
39
|
+
context "when service is down" do
|
40
|
+
let(:request){
|
41
|
+
exception = Faraday::Adapter::Test::Stubs.new do |stub|
|
42
|
+
%i(get put post delete).each do |method|
|
43
|
+
stub.send(method, '/failblog') {raise Faraday::Error::ConnectionFailed.new('Connection Failed')}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
request = Request.new do |conn|
|
47
|
+
conn.adapter :test, exception
|
48
|
+
end
|
49
|
+
request
|
50
|
+
}
|
51
|
+
|
42
52
|
%i(get put post delete).each do |method|
|
43
53
|
describe "#{method}" do
|
44
54
|
before do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plaza
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- VMC Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|