quinoa 0.0.1 → 0.0.2

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f516e7035e04e7295fdd2ac636b6a83293a0955c
4
- data.tar.gz: 0b96e381efab9a6136db80c504b8a6f88b653683
3
+ metadata.gz: b938e12968e4999711be95c44a665f6163139170
4
+ data.tar.gz: 387e243bd1aee8a36d04a3a89b1e9da15cf79338
5
5
  SHA512:
6
- metadata.gz: fa5296f9a90f574898db393d8854e06aa13d3a1add5c7ca943fdeaa72fee651059eb1a4b92cf57ff1ab688cbec90ca20363227780d673a022768d515301c63a5
7
- data.tar.gz: ca275212ccd74137f3e4ac3f51cd46aa0ee055e325957e2b4573450c4c021ec4ce8efaaee3f7d458b6cbe6fceb167a0eddbf0748e657950df435845329a95f1e
6
+ metadata.gz: c09655ca36ceeab843d0cffe5703366c783dce50fea9c9a5742d52aebed69b25d22de754ebd6a229af86f35dfb32fdbff7c324453dd1a832f6b3b96ed01f4c11
7
+ data.tar.gz: 72933486efb627933b7d339f9223959194c0142114a45d98407793954a96122fda1af782ca945f584fdb4655f1d7337dfbd31558d3a6c50f7e06aba6651b9868
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
+ *.swp
2
3
  *.rbc
3
4
  /.config
4
5
  /coverage/
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- quinoa (0.0.1)
4
+ quinoa (0.0.2)
5
5
  rest-client (~> 0)
6
6
  rspec (~> 0)
7
7
 
@@ -17,8 +17,6 @@ GEM
17
17
  simplecov (>= 0.7)
18
18
  term-ansicolor
19
19
  thor
20
- crack (0.4.2)
21
- safe_yaml (~> 1.0.0)
22
20
  cucumber (0.10.7)
23
21
  builder (>= 2.1.2)
24
22
  diff-lcs (>= 1.1.2)
@@ -40,7 +38,6 @@ GEM
40
38
  rake (0.9.6)
41
39
  rest-client (0.9.2)
42
40
  rspec (0.9.4)
43
- safe_yaml (1.0.4)
44
41
  simplecov (0.10.0)
45
42
  docile (~> 1.1.0)
46
43
  json (~> 1.8)
@@ -51,9 +48,8 @@ GEM
51
48
  tins (~> 1.0)
52
49
  thor (0.19.1)
53
50
  tins (1.6.0)
54
- webmock (1.21.0)
55
- addressable (>= 2.3.6)
56
- crack (>= 0.3.2)
51
+ webmock (0.9.1)
52
+ addressable (>= 2.1.1)
57
53
 
58
54
  PLATFORMS
59
55
  ruby
@@ -66,7 +62,7 @@ DEPENDENCIES
66
62
  quinoa!
67
63
  rake (~> 0)
68
64
  simplecov (~> 0)
69
- webmock
65
+ webmock (~> 0)
70
66
 
71
67
  BUNDLED WITH
72
68
  1.10.6
data/README.md CHANGED
@@ -1,5 +1,34 @@
1
- CELLO
1
+ quinoa
2
2
  =====
3
+ ![alt tag](http://i.huffpost.com/gen/1821327/images/n-QUINOA-large570.jpg)
4
+
5
+ Quinoa is a service-object model framework built on top of rest-client (https://github.com/rest-client/rest-client).
6
+ The idea is to define a rest endpoint and some details about it only once, and than reuse it with different payloads or properties.
7
+
8
+ For example, if I want to define a rest endpoint for the url http://www.camiloribeiro.com with the content-type application/json and send two different body payloads, I could do it like this:
9
+
10
+ camilo_test = Quinoa::Service.new "http://camiloribeiro.com"
11
+ camilo_test.content_type = "application/json"
12
+
13
+ camilo_test.body = '{ "foo":"bar"}'
14
+ result1 = camilo_test.post!
15
+
16
+ camilo_test.body = '{ "bar":"foo"}'
17
+ result2 = camilo_test.post!
18
+
19
+ Now if I want to change and use another endpoint in the same url, I can do something like this:
20
+
21
+ camilo_test.path = /new_endpoint
22
+ result3 = camilo_test.get!
23
+
24
+ To read the response it is as easy as setting the initial data:
25
+
26
+ result1.response_content_type
27
+ => "application/json"
28
+
29
+ result2.response_body
30
+ => "{ "some":"body"}
31
+
3
32
 
4
33
  LICENSE
5
34
  =======
data/changelog ADDED
@@ -0,0 +1,8 @@
1
+ 0.0,2: Adding tests for all response codes
2
+ - addind tests to make sure that we do not automatically fails when a 40X
3
+ or 50X wild response code apears
4
+
5
+ 0.0.1: Brand new version!
6
+ - Adding first version of the gem with basic operations post and get
7
+ - Possible to set content-type, body, accept and url
8
+ - Possible to read content-type, body and accept in the response object
@@ -3,21 +3,29 @@ require "rest-client"
3
3
  module Quinoa
4
4
  class Service
5
5
 
6
- attr_accessor :url, :content_type, :accept, :body, :response
6
+ attr_accessor :url, :content_type, :accept, :body, :response, :path
7
7
 
8
8
  def initialize url
9
+ self.path = ""
9
10
  self.url = url
10
11
  end
11
12
 
12
13
  def post!
13
- self.response = RestClient.post self.url, self.body, :accept => self.accept, :content_type => self.content_type
14
+ begin
15
+ self.response = RestClient.post self.url + self.path, self.body, :accept => self.accept, :content_type => self.content_type
16
+ rescue => e
17
+ self.response = e.response
18
+ end
14
19
  end
15
20
 
16
21
  def get!
17
- self.response = RestClient.get self.url, :accept => self.accept
22
+ begin
23
+ self.response = RestClient.get self.url + self.path, :accept => self.accept
24
+ rescue => e
25
+ self.response = e.response
26
+ end
18
27
  end
19
28
 
20
-
21
29
  def response_code
22
30
  self.response.code
23
31
  end
@@ -34,5 +42,9 @@ module Quinoa
34
42
  self.response.body
35
43
  end
36
44
 
45
+ def response_location
46
+ self.response.headers[:location]
47
+ end
48
+
37
49
  end
38
50
  end
@@ -1,3 +1,3 @@
1
1
  module Quinoa
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/quinoa.jpg ADDED
Binary file
@@ -11,73 +11,186 @@ describe Quinoa do
11
11
  it "Should instantiate" do
12
12
  expect(@service.url).to eq "http://www.camiloribeiro.com"
13
13
  end
14
-
14
+
15
15
  it "Should have a Content-Type" do
16
16
  expect(@service.content_type).to eq nil
17
-
17
+
18
18
  @service.content_type = "application/json"
19
19
  expect(@service.content_type).to eq "application/json"
20
20
  end
21
-
21
+
22
22
  it "Should have a Accept" do
23
23
  expect(@service.accept).to eq nil
24
-
24
+
25
25
  @service.accept = "application/xml;q=0.9,*/*;q=0.8."
26
26
  expect(@service.accept).to eq "application/xml;q=0.9,*/*;q=0.8."
27
27
  end
28
-
28
+
29
29
  it "Should have a body" do
30
30
  expect(@service.body).to eq nil
31
-
31
+
32
32
  @service.body = "text"
33
33
  expect(@service.body).to eq "text"
34
34
  end
35
35
 
36
36
  end
37
37
 
38
- describe "the service should have the basic behaviours of a service" do
39
38
 
40
- before(:each) do
41
- stub_request(:any, "http://www.camiloribeiro.com/").
42
- to_return(:status => 200, :body => "simple response", :headers => {:accept=>"application/xml", :content_type => "application/json"})
39
+ describe "defining a different paths" do
43
40
 
44
- @service = Quinoa::Service.new "http://www.camiloribeiro.com"
45
- @service.content_type = "application/json"
46
- @service.body = "simple body"
41
+ ["/", "/path"].each do |path|
42
+ describe "should work for the path #{path}" do
43
+
44
+ before(:each) do
45
+ stub_request(:any, "http://www.camiloribeiro.com#{path}").
46
+ to_return(:status => 200, :body => "simple response", :headers => {:accept=>"application/xml", :content_type => "application/json"})
47
47
 
48
- end
48
+ @service = Quinoa::Service.new "http://www.camiloribeiro.com"
49
+ @service.path = path
50
+ @service.content_type = "application/json"
51
+ @service.body = "simple body"
52
+
53
+ end
54
+
55
+ it "should post" do
56
+ @service.post!
57
+
58
+ # explicity
59
+ expect(@service.response.headers[:accept]).to eq("application/xml")
60
+ expect(@service.response.headers[:content_type]).to eq("application/json")
61
+ expect(@service.response.body).to eq("simple response")
62
+ expect(@service.response.code).to eq(200)
63
+
64
+ # natural
65
+ expect(@service.response_accept).to eq("application/xml")
66
+ expect(@service.response_content_type).to eq("application/json")
67
+ expect(@service.response_body).to eq("simple response")
68
+ expect(@service.response_code).to eq(200)
69
+ end
70
+
71
+ it "should get" do
72
+ @service.get!
73
+
74
+ # explicity
75
+ expect(@service.response.headers[:accept]).to eq("application/xml")
76
+ expect(@service.response.headers[:content_type]).to eq("application/json")
77
+ expect(@service.response.body).to eq("simple response")
78
+ expect(@service.response.code).to eq(200)
79
+
80
+ # natural
81
+ expect(@service.response_accept).to eq("application/xml")
82
+ expect(@service.response_content_type).to eq("application/json")
83
+ expect(@service.response_body).to eq("simple response")
84
+ expect(@service.response_code).to eq(200)
85
+ end
49
86
 
50
- it "should post" do
51
- @service.post!
52
-
53
- # explicity
54
- expect(@service.response.headers[:accept]).to eq("application/xml")
55
- expect(@service.response.headers[:content_type]).to eq("application/json")
56
- expect(@service.response.body).to eq("simple response")
57
- expect(@service.response.code).to eq(200)
58
-
59
- # natural
60
- expect(@service.response_accept).to eq("application/xml")
61
- expect(@service.response_content_type).to eq("application/json")
62
- expect(@service.response_body).to eq("simple response")
63
- expect(@service.response_code).to eq(200)
87
+
88
+ end
64
89
  end
90
+ end
91
+
92
+
93
+ describe "the service should have the basic behaviours of a service" do
94
+
95
+ # 303 post and get, 301 get, 302 get and 307 get failing
96
+ [100,101,102,200,201,202,203,204,205,206,207,208,226,300,304,305,306,308,308,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,420,421,422,423,424,426,428,429,431,440,444,449,450,451,451,494,495,496,497,498,499,499,500,501,502,503,504,505,506,507,508,509,510,511,520,522,598,599].each do |code|
97
+ describe "when returning code #{code}" do
98
+ before(:each) do
99
+ stub_request(:any, "http://www.camiloribeiro.com/").
100
+ to_return(:status => code, :body => "simple response", :headers => {:accept=>"application/xml", :content_type => "application/json"})
101
+
102
+ @service = Quinoa::Service.new "http://www.camiloribeiro.com"
103
+ @service.content_type = "application/json"
104
+ @service.body = "simple body"
105
+
106
+ end
107
+
108
+ it "should post" do
109
+ @service.post!
110
+
111
+ # explicity
112
+ expect(@service.response.headers[:accept]).to eq("application/xml")
113
+ expect(@service.response.headers[:content_type]).to eq("application/json")
114
+ expect(@service.response.body).to eq("simple response")
115
+ expect(@service.response.code).to eq(code)
116
+
117
+ # natural
118
+ expect(@service.response_accept).to eq("application/xml")
119
+ expect(@service.response_content_type).to eq("application/json")
120
+ expect(@service.response_body).to eq("simple response")
121
+ expect(@service.response_code).to eq(code)
122
+ end
123
+
124
+ it "should get" do
125
+ @service.get!
65
126
 
66
- it "should get" do
67
- @service.get!
127
+ # explicity
128
+ expect(@service.response.headers[:accept]).to eq("application/xml")
129
+ expect(@service.response.headers[:content_type]).to eq("application/json")
130
+ expect(@service.response.body).to eq("simple response")
131
+ expect(@service.response.code).to eq(code)
68
132
 
69
- # explicity
70
- expect(@service.response.headers[:accept]).to eq("application/xml")
71
- expect(@service.response.headers[:content_type]).to eq("application/json")
72
- expect(@service.response.body).to eq("simple response")
73
- expect(@service.response.code).to eq(200)
133
+ # natural
134
+ expect(@service.response_accept).to eq("application/xml")
135
+ expect(@service.response_content_type).to eq("application/json")
136
+ expect(@service.response_body).to eq("simple response")
137
+ expect(@service.response_code).to eq(code)
138
+ end
74
139
 
75
- # natural
76
- expect(@service.response_accept).to eq("application/xml")
77
- expect(@service.response_content_type).to eq("application/json")
78
- expect(@service.response_body).to eq("simple response")
79
- expect(@service.response_code).to eq(200)
140
+ end
80
141
  end
81
142
 
143
+ # 303 post and get, 301 get, 302 get and 307 get failing
144
+ [301,302,307].each do |code|
145
+ describe "when returning code #{code}" do
146
+ before(:each) do
147
+ stub_request(:any, "http://www.camiloribeiro.com/").
148
+ to_return(:status => code, :body => "simple response", :headers => {:accept=>"application/xml", :content_type => "application/json", :location => "http://www.bugbang.com.br"})
149
+
150
+ stub_request(:any, "http://www.bugbang.com.br/").
151
+ to_return(:status => 200, :body => "followed redirect", :headers => {:accept=>"application/xml", :content_type => "application/json"})
152
+
153
+ @service = Quinoa::Service.new "http://www.camiloribeiro.com"
154
+ @service.content_type = "application/json"
155
+ @service.body = "simple body"
156
+
157
+ end
158
+
159
+ it "should post" do
160
+ @service.post!
161
+
162
+ # explicity
163
+ expect(@service.response.headers[:accept]).to eq("application/xml")
164
+ expect(@service.response.headers[:content_type]).to eq("application/json")
165
+ expect(@service.response.body).to eq("simple response")
166
+ expect(@service.response.headers[:location]).to eq("http://www.bugbang.com.br")
167
+ expect(@service.response.code).to eq(code)
168
+
169
+ # natural
170
+ expect(@service.response_accept).to eq("application/xml")
171
+ expect(@service.response_content_type).to eq("application/json")
172
+ expect(@service.response_body).to eq("simple response")
173
+ expect(@service.response_location).to eq("http://www.bugbang.com.br")
174
+ expect(@service.response_code).to eq(code)
175
+ end
176
+
177
+ it "should get" do
178
+ @service.get!
179
+
180
+ # explicity
181
+ expect(@service.response.headers[:accept]).to eq("application/xml")
182
+ expect(@service.response.headers[:content_type]).to eq("application/json")
183
+ expect(@service.response.body).to eq("followed redirect")
184
+ expect(@service.response.code).to eq(200)
185
+
186
+ # natural
187
+ expect(@service.response_accept).to eq("application/xml")
188
+ expect(@service.response_content_type).to eq("application/json")
189
+ expect(@service.response_body).to eq("followed redirect")
190
+ expect(@service.response_code).to eq(200)
191
+ end
192
+
193
+ end
194
+ end
82
195
  end
83
196
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quinoa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Camilo Ribeiro
@@ -153,10 +153,12 @@ files:
153
153
  - LICENSE
154
154
  - README.md
155
155
  - Rakefile
156
+ - changelog
156
157
  - lib/quinoa.rb
157
158
  - lib/quinoa/service.rb
158
159
  - lib/quinoa/version.rb
159
160
  - quinoa.gemspec
161
+ - quinoa.jpg
160
162
  - spec/service_object_spec.rb
161
163
  - spec/spec_helper.rb
162
164
  homepage: http://github.com/camiloribeiro/quinoa