siren_client 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -6
- data/lib/siren_client.rb +0 -1
- data/lib/siren_client/action.rb +10 -9
- data/lib/siren_client/base.rb +1 -20
- data/lib/siren_client/entity.rb +9 -6
- data/lib/siren_client/exceptions.rb +0 -1
- data/lib/siren_client/link.rb +3 -3
- data/lib/siren_client/modules/with_raw_response.rb +3 -3
- data/lib/siren_client/raw_response.rb +7 -1
- data/lib/siren_client/version.rb +1 -1
- data/spec/live/traverse_spec.rb +25 -5
- data/spec/support/endpoints/concepts.rb +22 -12
- data/spec/support/endpoints/messages.rb +73 -0
- data/spec/support/endpoints/root.rb +26 -38
- data/spec/unit/action_spec.rb +25 -5
- data/spec/unit/base_spec.rb +1 -27
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bb4a69b5cf6283d4600e932cdff36f0a6b491c1
|
4
|
+
data.tar.gz: cc297a74136cff297fe049b4bfc7f44a3a45b8c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f78a0a0b758d5c5374e35d4871c895103847e81436f8224f1d2a1009642d6e2a52ec256dfbfe6b70abb10d7de448c8b7a5b87527d84d1936df21aa0f5638399b
|
7
|
+
data.tar.gz: 88d809060672563d5e1a7d1daaed24fe005eba79eabc4f1e63bb1328534f5a0a21d0b54ba104d879a6628cb311b8dbf43c537379b6bcb3b2905525b05935039d
|
data/.travis.yml
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
before_install:
|
2
|
-
- 'if [[ "$TRAVIS_RUBY_VERSION" =~ "jruby" ]]; then rvm get head && rvm reload && rvm use --install $TRAVIS_RUBY_VERSION; fi'
|
3
1
|
language: ruby
|
4
2
|
rvm:
|
5
|
-
-
|
6
|
-
-
|
7
|
-
-
|
8
|
-
-
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.0
|
6
|
+
- 2.2.0
|
9
7
|
- jruby-19mode
|
10
8
|
- jruby-9.0.5.0
|
11
9
|
script: bundle exec rspec
|
data/lib/siren_client.rb
CHANGED
data/lib/siren_client/action.rb
CHANGED
@@ -12,7 +12,7 @@ module SirenClient
|
|
12
12
|
end
|
13
13
|
@payload = data
|
14
14
|
|
15
|
-
@config = { format: :json }.merge config
|
15
|
+
@config = { format: :json }.merge config
|
16
16
|
@name = @payload['name'] || ''
|
17
17
|
@classes = @payload['class'] || []
|
18
18
|
@method = (@payload['method'] || 'GET').downcase
|
@@ -34,17 +34,15 @@ module SirenClient
|
|
34
34
|
end
|
35
35
|
options[:headers]['Content-Type'] = @type
|
36
36
|
begin
|
37
|
-
|
38
|
-
SirenClient.logger.debug "#{@method.upcase} #{@href}#{query}"
|
39
|
-
options[:headers].each do |k, v|
|
40
|
-
SirenClient.logger.debug " #{k}: #{v}"
|
41
|
-
end
|
42
|
-
SirenClient.logger.debug ' ' + options[:body].to_query unless options[:body].empty?
|
37
|
+
resp = generate_raw_response(@method, self.href, options)
|
43
38
|
if next_response_is_raw?
|
44
39
|
disable_raw_response
|
45
|
-
|
40
|
+
resp
|
46
41
|
else
|
47
|
-
|
42
|
+
if resp.parsed_response.nil?
|
43
|
+
raise InvalidResponseError.new "Response could not be parsed. Code=#{resp.code} Message=\"#{resp.message}\" Body=#{resp.body}"
|
44
|
+
end
|
45
|
+
Entity.new(resp.parsed_response, @config)
|
48
46
|
end
|
49
47
|
rescue URI::InvalidURIError => e
|
50
48
|
raise InvalidURIError, e.message
|
@@ -52,5 +50,8 @@ module SirenClient
|
|
52
50
|
raise InvalidResponseError, e.message
|
53
51
|
end
|
54
52
|
end
|
53
|
+
# `.submit` should be used with actions that
|
54
|
+
# don't require any parameters, for readability.
|
55
|
+
alias_method :submit, :where
|
55
56
|
end
|
56
57
|
end
|
data/lib/siren_client/base.rb
CHANGED
@@ -1,30 +1,11 @@
|
|
1
1
|
module SirenClient
|
2
|
-
# Add a logger that gets passed in from an outside source
|
3
|
-
# or default to a standard logger. This will allow different
|
4
|
-
# setups i.e. java logging to log wherever/however they wish.
|
5
|
-
@@logger = Logger.new(STDOUT)
|
6
|
-
@@logger.level = Logger::WARN
|
7
|
-
@@logger.progname = 'SirenClient.' + SirenClient::VERSION
|
8
|
-
def self.logger; @@logger; end
|
9
|
-
def self.logger=(log)
|
10
|
-
unless log.respond_to?(:debug) &&
|
11
|
-
log.respond_to?(:info) &&
|
12
|
-
log.respond_to?(:warn) &&
|
13
|
-
log.respond_to?(:error) &&
|
14
|
-
log.respond_to?(:fatal)
|
15
|
-
raise InvalidLogger, "The logger object does not respond to [:debug, :info, :warn, :error, :fatal]."
|
16
|
-
end
|
17
|
-
@@logger = log
|
18
|
-
@@logger.progname = 'SirenClient.' + SirenClient::VERSION
|
19
|
-
end
|
20
|
-
|
21
2
|
def self.get(options)
|
22
3
|
if options.is_a? String
|
23
4
|
Entity.new(options)
|
24
5
|
elsif options.is_a? Hash
|
25
6
|
url = options[:url] || options['url']
|
26
7
|
raise ArgumentError, "You must supply a valid url to SirenClient.get" unless url
|
27
|
-
Entity.new(url, options)
|
8
|
+
Entity.new(url, options)
|
28
9
|
else
|
29
10
|
raise ArgumentError, 'You must supply either a string or hash to SirenClient.get'
|
30
11
|
end
|
data/lib/siren_client/entity.rb
CHANGED
@@ -16,8 +16,11 @@ module SirenClient
|
|
16
16
|
raise InvalidURIError, 'An invalid url was passed to SirenClient::Entity.new.'
|
17
17
|
end
|
18
18
|
begin
|
19
|
-
|
20
|
-
|
19
|
+
resp = generate_raw_response(:get, data, @config)
|
20
|
+
if resp.parsed_response.nil?
|
21
|
+
raise InvalidResponseError.new "Response could not be parsed. Code=#{resp.code} Message=\"#{resp.message}\" Body=#{resp.body}"
|
22
|
+
end
|
23
|
+
@payload = resp.parsed_response
|
21
24
|
rescue URI::InvalidURIError => e
|
22
25
|
raise InvalidURIError, e.message
|
23
26
|
rescue JSON::ParserError => e
|
@@ -39,8 +42,8 @@ module SirenClient
|
|
39
42
|
else
|
40
43
|
if next_response_is_raw?
|
41
44
|
disable_raw_response
|
42
|
-
@entities[i].with_raw_response.go
|
43
|
-
else
|
45
|
+
@entities[i].with_raw_response.go
|
46
|
+
else
|
44
47
|
@entities[i].go
|
45
48
|
end
|
46
49
|
end
|
@@ -72,7 +75,7 @@ module SirenClient
|
|
72
75
|
return if self.href.empty?
|
73
76
|
if next_response_is_raw?
|
74
77
|
disable_raw_response
|
75
|
-
generate_raw_response(self.href, @config)
|
78
|
+
generate_raw_response(:get, self.href, @config)
|
76
79
|
else
|
77
80
|
self.class.new(self.href, @config)
|
78
81
|
end
|
@@ -103,7 +106,7 @@ module SirenClient
|
|
103
106
|
disable_raw_response
|
104
107
|
return link.with_raw_response.go
|
105
108
|
else
|
106
|
-
return link.go
|
109
|
+
return link.go
|
107
110
|
end
|
108
111
|
end
|
109
112
|
end
|
data/lib/siren_client/link.rb
CHANGED
@@ -4,14 +4,14 @@ module SirenClient
|
|
4
4
|
|
5
5
|
attr_accessor :href
|
6
6
|
attr_reader :payload, :rels, :title, :type, :config
|
7
|
-
|
7
|
+
|
8
8
|
def initialize(data, config={})
|
9
9
|
super()
|
10
10
|
if data.class != Hash
|
11
11
|
raise ArgumentError, "You must pass in a Hash to SirenClient::Link.new"
|
12
12
|
end
|
13
13
|
@payload = data
|
14
|
-
@config = { format: :json }.merge config
|
14
|
+
@config = { format: :json }.merge config
|
15
15
|
|
16
16
|
@rels = @payload['rel'] || []
|
17
17
|
@href = @payload['href'] || ''
|
@@ -22,7 +22,7 @@ module SirenClient
|
|
22
22
|
def go
|
23
23
|
if next_response_is_raw?
|
24
24
|
disable_raw_response
|
25
|
-
generate_raw_response(self.href, @config)
|
25
|
+
generate_raw_response(:get, self.href, @config)
|
26
26
|
else
|
27
27
|
Entity.new(self.href, @config)
|
28
28
|
end
|
@@ -18,10 +18,10 @@ module SirenClient
|
|
18
18
|
@_next_response_is_raw
|
19
19
|
end
|
20
20
|
|
21
|
-
private
|
21
|
+
private
|
22
22
|
|
23
|
-
def generate_raw_response(url, config)
|
24
|
-
RawResponse.new HTTParty.
|
23
|
+
def generate_raw_response(method, url, config)
|
24
|
+
RawResponse.new HTTParty.send(method.to_sym, url, config)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module SirenClient
|
2
2
|
class RawResponse
|
3
|
+
attr_accessor :response
|
4
|
+
|
3
5
|
def initialize(http_res)
|
4
6
|
unless http_res.class == HTTParty::Response
|
5
7
|
raise InvalidResponseError, "SirenClient::RawResponse expects a HTTParty::Response instance."
|
@@ -7,8 +9,12 @@ module SirenClient
|
|
7
9
|
@response = http_res
|
8
10
|
end
|
9
11
|
|
12
|
+
def parsed_response
|
13
|
+
@response.parsed_response
|
14
|
+
end
|
15
|
+
|
10
16
|
def body
|
11
|
-
@response.body
|
17
|
+
@response.body
|
12
18
|
end
|
13
19
|
|
14
20
|
def code
|
data/lib/siren_client/version.rb
CHANGED
data/spec/live/traverse_spec.rb
CHANGED
@@ -12,7 +12,7 @@ end
|
|
12
12
|
|
13
13
|
describe SirenClient do
|
14
14
|
context 'when creating an entity' do
|
15
|
-
let (:headers_ent) {
|
15
|
+
let (:headers_ent) {
|
16
16
|
SirenClient.get({
|
17
17
|
url: URL,
|
18
18
|
basic_auth: { username: 'admin', password: '1234' },
|
@@ -22,7 +22,7 @@ describe SirenClient do
|
|
22
22
|
it 'can set HTTP headers' do
|
23
23
|
expect {
|
24
24
|
expect(headers_ent.config[:headers]).to be_a Hash
|
25
|
-
expect(headers_ent.config[:headers]).to eq({
|
25
|
+
expect(headers_ent.config[:headers]).to eq({
|
26
26
|
"Accept" => "application/json"
|
27
27
|
})
|
28
28
|
}.to_not raise_error
|
@@ -34,14 +34,14 @@ describe SirenClient do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
let (:client) {
|
37
|
+
let (:client) {
|
38
38
|
|
39
39
|
SirenClient.get(
|
40
|
-
url: URL,
|
40
|
+
url: URL,
|
41
41
|
timeout: 2,
|
42
42
|
basic_auth: { username: 'admin', password: '1234' },
|
43
43
|
headers: { "Accept" => "application/json" }
|
44
|
-
)
|
44
|
+
)
|
45
45
|
}
|
46
46
|
context 'when accessing the root entity' do
|
47
47
|
it 'to return an entity' do
|
@@ -97,6 +97,21 @@ describe SirenClient do
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
end
|
100
|
+
context 'when executing an action with DELETE' do
|
101
|
+
it 'returns a siren response' do
|
102
|
+
expect(client.delete_concept.where(id: 1)).to be_a SirenClient::Entity
|
103
|
+
end
|
104
|
+
end
|
105
|
+
# Typically this will be called directly on a resource
|
106
|
+
# without any additional parameters.
|
107
|
+
context 'when executing a `text/plain` action' do
|
108
|
+
it 'returns a 404 without the body being set correctly' do
|
109
|
+
expect { client.messages[0].update_message.submit }.to raise_error(/Code=404/)
|
110
|
+
end
|
111
|
+
it 'returns a siren response' do
|
112
|
+
expect(client.messages[0].update_message.where('this is the new message')).to be_a SirenClient::Entity
|
113
|
+
end
|
114
|
+
end
|
100
115
|
|
101
116
|
let (:concepts) { SirenClient.get({ url: URL, basic_auth: { username: 'admin', password: '1234' }}).concepts }
|
102
117
|
context 'when accessing an entity' do
|
@@ -123,6 +138,11 @@ describe SirenClient do
|
|
123
138
|
client.filter_concepts_get.with_raw_response.where(params)
|
124
139
|
expect(client.concepts).to be_a SirenClient::Entity
|
125
140
|
end
|
141
|
+
it 'to return the correct concept' do
|
142
|
+
concepts_raw = client.filter_concepts_get.with_raw_response.where(params)
|
143
|
+
expect(concepts_raw.body).to match(/"count": 1/)
|
144
|
+
expect(concepts_raw.body).to match(/("text":"barack obama"){1}/)
|
145
|
+
end
|
126
146
|
end
|
127
147
|
it 'to provide the raw body' do
|
128
148
|
expect(client.with_raw_response.concepts.body).to eq(HTTParty.get(URL + '/concepts', basic_auth: { username: 'admin', password: '1234' }).body)
|
@@ -1,14 +1,15 @@
|
|
1
1
|
class TestServer < Sinatra::Base
|
2
2
|
CON_1 = <<-EOF
|
3
|
-
{
|
3
|
+
{
|
4
4
|
"class":["concepts"],
|
5
5
|
"rel":["/rels/concepts"],
|
6
|
-
"properties":{
|
6
|
+
"properties":{
|
7
|
+
"id": 1,
|
7
8
|
"text":"barack obama",
|
8
9
|
"category":"PERSON"
|
9
10
|
},
|
10
|
-
"links":[
|
11
|
-
{
|
11
|
+
"links":[
|
12
|
+
{
|
12
13
|
"rel":["self"],
|
13
14
|
"href":"#{@@url}/concepts/1"
|
14
15
|
}
|
@@ -16,15 +17,16 @@ class TestServer < Sinatra::Base
|
|
16
17
|
}
|
17
18
|
EOF
|
18
19
|
CON_2 = <<-EOF
|
19
|
-
{
|
20
|
+
{
|
20
21
|
"class":["concepts"],
|
21
22
|
"rel":["/rels/concepts"],
|
22
|
-
"properties":{
|
23
|
+
"properties":{
|
24
|
+
"id": 2,
|
23
25
|
"text":"tennessee",
|
24
26
|
"category":"LOCATION"
|
25
27
|
},
|
26
|
-
"links":[
|
27
|
-
{
|
28
|
+
"links":[
|
29
|
+
{
|
28
30
|
"rel":["self"],
|
29
31
|
"href":"#{@@url}/concepts/2"
|
30
32
|
}
|
@@ -47,6 +49,14 @@ class TestServer < Sinatra::Base
|
|
47
49
|
}
|
48
50
|
EOF
|
49
51
|
end
|
52
|
+
delete '/concepts/?' do
|
53
|
+
<<-EOF
|
54
|
+
{
|
55
|
+
"class":["status"],
|
56
|
+
"properties": { "success": true }
|
57
|
+
}
|
58
|
+
EOF
|
59
|
+
end
|
50
60
|
get '/concepts/?' do
|
51
61
|
query = (request.query_string.length > 0 ? '?' : '') + request.query_string
|
52
62
|
# search=obama
|
@@ -66,14 +76,14 @@ class TestServer < Sinatra::Base
|
|
66
76
|
EOF
|
67
77
|
else
|
68
78
|
<<-EOF
|
69
|
-
{
|
79
|
+
{
|
70
80
|
"class":["concepts","collection"],
|
71
|
-
"properties":{
|
81
|
+
"properties":{
|
72
82
|
"count":2
|
73
83
|
},
|
74
84
|
"entities":[#{CON_1}, #{CON_2}],
|
75
|
-
"links":[
|
76
|
-
{
|
85
|
+
"links":[
|
86
|
+
{
|
77
87
|
"rel":["self"],
|
78
88
|
"href":"#{@@url}/concepts#{query}"
|
79
89
|
}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class TestServer < Sinatra::Base
|
2
|
+
MSG_1 = <<-EOF
|
3
|
+
{
|
4
|
+
"class":["messages"],
|
5
|
+
"rel":["/rels/messages"],
|
6
|
+
"properties":{
|
7
|
+
"id": 1,
|
8
|
+
"text":"This is message one"
|
9
|
+
},
|
10
|
+
"links":[
|
11
|
+
{
|
12
|
+
"rel":["self"],
|
13
|
+
"href":"#{@@url}/messages/1"
|
14
|
+
}
|
15
|
+
],
|
16
|
+
"actions": [{
|
17
|
+
"name": "update message",
|
18
|
+
"method": "PUT",
|
19
|
+
"href": "#{@@url}/messages/1",
|
20
|
+
"title": "Update the text of the message",
|
21
|
+
"type": "text/plain"
|
22
|
+
}]
|
23
|
+
}
|
24
|
+
EOF
|
25
|
+
MSG_2 = <<-EOF
|
26
|
+
{
|
27
|
+
"class":["messages"],
|
28
|
+
"rel":["/rels/messages"],
|
29
|
+
"properties":{
|
30
|
+
"id": 2,
|
31
|
+
"text":"This is message two"
|
32
|
+
},
|
33
|
+
"links":[
|
34
|
+
{
|
35
|
+
"rel":["self"],
|
36
|
+
"href":"#{@@url}/messages/2"
|
37
|
+
}
|
38
|
+
],
|
39
|
+
"actions": [{
|
40
|
+
"name": "update message",
|
41
|
+
"method": "PUT",
|
42
|
+
"href": "#{@@url}/messages/2",
|
43
|
+
"title": "Update the text of the message",
|
44
|
+
"type": "text/plain"
|
45
|
+
}]
|
46
|
+
}
|
47
|
+
EOF
|
48
|
+
put '/messages/:id' do
|
49
|
+
if request.content_type == 'text/plain' &&
|
50
|
+
request.body.read == 'this is the new message'
|
51
|
+
MSG_1
|
52
|
+
else
|
53
|
+
halt 404
|
54
|
+
end
|
55
|
+
end
|
56
|
+
get '/messages/?' do
|
57
|
+
<<-EOF
|
58
|
+
{
|
59
|
+
"class":["messages","collection"],
|
60
|
+
"properties":{
|
61
|
+
"count":2
|
62
|
+
},
|
63
|
+
"entities":[#{MSG_1}, #{MSG_2}],
|
64
|
+
"links":[
|
65
|
+
{
|
66
|
+
"rel":["self"],
|
67
|
+
"href":"#{@@url}/messages"
|
68
|
+
}
|
69
|
+
]
|
70
|
+
}
|
71
|
+
EOF
|
72
|
+
end
|
73
|
+
end
|
@@ -12,12 +12,12 @@ class TestServer < Sinatra::Base
|
|
12
12
|
"href":"#{@@url}/"
|
13
13
|
},
|
14
14
|
{
|
15
|
-
"rel": ["collection", "concepts"],
|
15
|
+
"rel": ["collection", "concepts"],
|
16
16
|
"href":"#{@@url}/concepts",
|
17
17
|
"title": "Concepts"
|
18
18
|
},
|
19
19
|
{
|
20
|
-
"rel": ["collection", "concepts with spaces"],
|
20
|
+
"rel": ["collection", "concepts with spaces"],
|
21
21
|
"href":"#{@@url}/concepts",
|
22
22
|
"title": "Concepts"
|
23
23
|
},
|
@@ -26,80 +26,68 @@ class TestServer < Sinatra::Base
|
|
26
26
|
"title":"Messages"
|
27
27
|
}
|
28
28
|
],
|
29
|
-
"actions": [
|
30
|
-
{
|
29
|
+
"actions": [
|
30
|
+
{
|
31
31
|
"name":"filter-concepts-get",
|
32
32
|
"method":"GET",
|
33
33
|
"href":"#{@@url}/concepts",
|
34
34
|
"title":"Get an optionally filtered list of Concepts",
|
35
35
|
"type":"application/x-www-form-urlencoded",
|
36
|
-
"fields":[
|
37
|
-
{
|
36
|
+
"fields":[
|
37
|
+
{
|
38
38
|
"name":"limit",
|
39
39
|
"title":"Max number of results in each page",
|
40
40
|
"type":"number"
|
41
41
|
},
|
42
|
-
{
|
42
|
+
{
|
43
43
|
"name":"page",
|
44
44
|
"title":"Page number, starting at 1",
|
45
45
|
"type":"number"
|
46
46
|
},
|
47
|
-
{
|
47
|
+
{
|
48
48
|
"name":"search",
|
49
49
|
"title":"Keyword search on concept text",
|
50
50
|
"type":"text"
|
51
51
|
}
|
52
52
|
]
|
53
53
|
},
|
54
|
-
{
|
54
|
+
{
|
55
|
+
"name": "delete-concept",
|
56
|
+
"method": "DELETE",
|
57
|
+
"href": "#{@@url}/concepts",
|
58
|
+
"title": "Delete a concept",
|
59
|
+
"type": "application/x-www-form-urlencoded",
|
60
|
+
"fields": [{
|
61
|
+
"name": "id",
|
62
|
+
"title": "ID of the concept to delete.",
|
63
|
+
"type": "text"
|
64
|
+
}]
|
65
|
+
},
|
66
|
+
{
|
55
67
|
"name":"filter-concepts-post",
|
56
68
|
"method":"POST",
|
57
69
|
"href":"#{@@url}/concepts",
|
58
70
|
"title":"Get an optionally filtered list of Concepts",
|
59
71
|
"type":"application/x-www-form-urlencoded",
|
60
|
-
"fields":[
|
61
|
-
{
|
72
|
+
"fields":[
|
73
|
+
{
|
62
74
|
"name":"limit",
|
63
75
|
"title":"Max number of results in each page",
|
64
76
|
"type":"number"
|
65
77
|
},
|
66
|
-
{
|
78
|
+
{
|
67
79
|
"name":"page",
|
68
80
|
"title":"Page number, starting at 1",
|
69
81
|
"type":"number"
|
70
82
|
},
|
71
|
-
{
|
83
|
+
{
|
72
84
|
"name":"search",
|
73
85
|
"title":"Keyword search on concept text",
|
74
86
|
"type":"text"
|
75
87
|
}
|
76
88
|
]
|
77
89
|
},
|
78
|
-
{ "name": "filter concepts post with spaces" }
|
79
|
-
{
|
80
|
-
"name":"filter-messages",
|
81
|
-
"method":"GET",
|
82
|
-
"href":"#{@@url}/messages",
|
83
|
-
"title":"Get an optionally filtered list of Messages",
|
84
|
-
"type":"application/x-www-form-urlencoded",
|
85
|
-
"fields":[
|
86
|
-
{
|
87
|
-
"name":"limit",
|
88
|
-
"title":"Max number of results in each page",
|
89
|
-
"type":"number"
|
90
|
-
},
|
91
|
-
{
|
92
|
-
"name":"page",
|
93
|
-
"title":"Page number, starting at 1",
|
94
|
-
"type":"number"
|
95
|
-
},
|
96
|
-
{
|
97
|
-
"name":"search",
|
98
|
-
"title":"Keyword search on message body",
|
99
|
-
"type":"number"
|
100
|
-
}
|
101
|
-
]
|
102
|
-
}
|
90
|
+
{ "name": "filter concepts post with spaces" }
|
103
91
|
]
|
104
92
|
}
|
105
93
|
EOF
|
data/spec/unit/action_spec.rb
CHANGED
@@ -2,6 +2,8 @@ require 'helper/spec_helper'
|
|
2
2
|
|
3
3
|
describe SirenClient::Action do
|
4
4
|
let (:action_data) { {"name"=>"search","method"=>"GET","href"=>"http://example.com/products","fields"=>[{"name"=>"search","type"=>"text"}]} }
|
5
|
+
let (:action_data_post) { {"name"=>"search","method"=>"POST","href"=>"http://example.com/products","fields"=>[{"name"=>"search","type"=>"text"}]} }
|
6
|
+
let (:action_data_delete) { {"name"=>"delete","method"=>"DELETE","href"=>"http://example.com/products"} }
|
5
7
|
|
6
8
|
describe '.new(data)' do
|
7
9
|
it 'raise an error if wrong type is provided' do
|
@@ -12,11 +14,17 @@ describe SirenClient::Action do
|
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
15
|
-
let (:action) {
|
16
|
-
SirenClient::Action.new(action_data, {
|
17
|
-
headers: { "Accept" => "application/json" }
|
17
|
+
let (:action) {
|
18
|
+
SirenClient::Action.new(action_data, {
|
19
|
+
headers: { "Accept" => "application/json" }
|
18
20
|
})
|
19
21
|
}
|
22
|
+
let (:action_post) {
|
23
|
+
SirenClient::Action.new(action_data_post)
|
24
|
+
}
|
25
|
+
let (:action_delete) {
|
26
|
+
SirenClient::Action.new(action_data_delete)
|
27
|
+
}
|
20
28
|
describe '.config' do
|
21
29
|
it 'is a hash' do
|
22
30
|
expect(action.config).to be_a Hash
|
@@ -81,10 +89,22 @@ describe SirenClient::Action do
|
|
81
89
|
end
|
82
90
|
end
|
83
91
|
describe '.where(params)' do
|
84
|
-
it 'executes the action
|
92
|
+
it 'executes the GET action' do
|
93
|
+
# I'm expecting an error here, all I want to see is that the url it being traversed.
|
94
|
+
expect { action.where(test: 'hi') }.to raise_error SirenClient::InvalidResponseError
|
95
|
+
end
|
96
|
+
it 'executes the POST action' do
|
85
97
|
# I'm expecting an error here, all I want to see is that the url it being traversed.
|
86
|
-
expect {
|
98
|
+
expect { action_post.where(test: 'hi') }.to raise_error SirenClient::InvalidResponseError
|
99
|
+
end
|
100
|
+
it 'executes the DELETE action' do
|
101
|
+
expect { action_delete.submit }.to raise_error SirenClient::InvalidResponseError
|
87
102
|
end
|
88
103
|
# The rest will be tested in the live specs.
|
89
104
|
end
|
105
|
+
describe '.submit' do
|
106
|
+
it 'executes the action without any parameters' do
|
107
|
+
expect { action.submit }.to raise_error SirenClient::InvalidResponseError
|
108
|
+
end
|
109
|
+
end
|
90
110
|
end
|
data/spec/unit/base_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe SirenClient do
|
|
9
9
|
expect { SirenClient.get }.to raise_error(ArgumentError)
|
10
10
|
end
|
11
11
|
it "raise an error if an improper param is provided" do
|
12
|
-
expect { SirenClient.get([1, 2, 3]) }.to raise_error(ArgumentError, invalid_param_msg)
|
12
|
+
expect { SirenClient.get([1, 2, 3]) }.to raise_error(ArgumentError, invalid_param_msg)
|
13
13
|
expect { SirenClient.get(nil) }.to raise_error(ArgumentError, invalid_param_msg)
|
14
14
|
end
|
15
15
|
it "raise an error if no url is provided" do
|
@@ -22,31 +22,5 @@ describe SirenClient do
|
|
22
22
|
expect { SirenClient.get('http://google.com') }.to raise_error(SirenClient::InvalidResponseError)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
describe '.logger(before)' do
|
26
|
-
it 'is a standard ruby logger instance' do
|
27
|
-
expect(SirenClient.logger).to be_a Logger
|
28
|
-
end
|
29
|
-
end
|
30
|
-
describe '.logger=' do
|
31
|
-
it 'raise an error if it does not respect the logger interface' do
|
32
|
-
expect { SirenClient.logger = "error" }.to raise_error SirenClient::InvalidLogger
|
33
|
-
end
|
34
|
-
it 'accepts an instance that respects the logger interface' do
|
35
|
-
SirenClient.logger = Logger.new(STDOUT)
|
36
|
-
SirenClient.logger.level = Logger::WARN
|
37
|
-
expect(SirenClient.logger).to be_a Logger
|
38
|
-
end
|
39
|
-
end
|
40
|
-
describe '.logger(after)' do
|
41
|
-
it 'responds to .info(str)' do
|
42
|
-
expect(SirenClient.logger.respond_to?(:info)).to eq(true)
|
43
|
-
end
|
44
|
-
it 'responds to .warn(str)' do
|
45
|
-
expect(SirenClient.logger.respond_to?(:warn)).to eq(true)
|
46
|
-
end
|
47
|
-
it 'responds to .error(str)' do
|
48
|
-
expect(SirenClient.logger.respond_to?(:error)).to eq(true)
|
49
|
-
end
|
50
|
-
end
|
51
25
|
# Remainder will be tested in live spec
|
52
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: siren_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chason Choate
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -198,6 +198,7 @@ files:
|
|
198
198
|
- spec/helper/spec_helper.rb
|
199
199
|
- spec/live/traverse_spec.rb
|
200
200
|
- spec/support/endpoints/concepts.rb
|
201
|
+
- spec/support/endpoints/messages.rb
|
201
202
|
- spec/support/endpoints/root.rb
|
202
203
|
- spec/support/test_server.rb
|
203
204
|
- spec/unit/action_spec.rb
|
@@ -226,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
227
|
version: '0'
|
227
228
|
requirements: []
|
228
229
|
rubyforge_project:
|
229
|
-
rubygems_version: 2.
|
230
|
+
rubygems_version: 2.4.8
|
230
231
|
signing_key:
|
231
232
|
specification_version: 4
|
232
233
|
summary: A client to traverse Siren APIs https://github.com/kevinswiber/siren
|
@@ -235,6 +236,7 @@ test_files:
|
|
235
236
|
- spec/helper/spec_helper.rb
|
236
237
|
- spec/live/traverse_spec.rb
|
237
238
|
- spec/support/endpoints/concepts.rb
|
239
|
+
- spec/support/endpoints/messages.rb
|
238
240
|
- spec/support/endpoints/root.rb
|
239
241
|
- spec/support/test_server.rb
|
240
242
|
- spec/unit/action_spec.rb
|