siren_client 0.2.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f38d3c4581d5764d0798e4c4d3908f7404ca7cdb
4
- data.tar.gz: 3e71628070a1391ef839335602ef778b1d1d7d94
3
+ metadata.gz: 4925d2e19eecb6f0cf7cc864099089e0b6f18fa3
4
+ data.tar.gz: f277ababef5cee15f59c437dd6c20e1b84873aa7
5
5
  SHA512:
6
- metadata.gz: 7edd967f314c6d036d7cfdef8889fd9953b1e0b19523343d71d0e5f1586d7f9438f44e01051aabb4e53e4d5489e6d01aca5f55196494bf89fdb4ecf5897065ec
7
- data.tar.gz: 043795907a4f6166549f42f9776447a1566d8e7f47f1f7995e47826f500e467eee0e904fd50c7a4209241b2022bcbe353c0436cc78c5e00d658dc35c04d3d579
6
+ metadata.gz: 4532ad1cdb6fbab5ae42a02127ebba0ec2610268dde0bfbe62d0c07850704c35f93a45f79018ba81de54a623802665c7b0a49b7c94cef3dbd66637ebddceccc9
7
+ data.tar.gz: d71716ea6cad51b955cad7ec2b8c9467fa2d0a81f51056d49b9b0431314a5958895187ca26022b11fa41737f8d6f843569c23a0490afd736eb4b0564b50e90a5
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .byebug_history
data/.travis.yml CHANGED
@@ -1,3 +1,5 @@
1
+ before_install:
2
+ - 'if [[ "$TRAVIS_RUBY_VERSION" =~ "jruby" ]]; then rvm get head && rvm reload && rvm use --install $TRAVIS_RUBY_VERSION; fi'
1
3
  language: ruby
2
4
  rvm:
3
5
  - "1.9.3"
@@ -5,4 +7,5 @@ rvm:
5
7
  - "2.1.0"
6
8
  - "2.2.0"
7
9
  - jruby-19mode
10
+ - jruby-9.0.5.0
8
11
  script: bundle exec rspec
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # SirenClient [![Build Status](https://travis-ci.org/cha55son/siren_client.svg)](https://travis-ci.org/cha55son/siren_client)
1
+ # SirenClient [![Build Status](https://travis-ci.org/cha55son/siren_client.svg)](https://travis-ci.org/cha55son/siren_client) [![Coverage Status](https://coveralls.io/repos/cha55son/siren_client/badge.svg)](https://coveralls.io/r/cha55son/siren_client)
2
2
 
3
3
  A simple client for traversing Siren APIs. Not sure what Siren is? View the spec here: https://github.com/kevinswiber/siren.
4
4
 
@@ -13,8 +13,9 @@ require 'siren_client'
13
13
  root = SirenClient.get('http://siren-api.example.com')
14
14
 
15
15
  # Advanced usage
16
- root = SirenClient.get('http://siren-api.example.com', {
17
- headers: { "Accept": "application/json", ... },
16
+ root = SirenClient.get({
17
+ url: 'http://siren-api.example.com',
18
+ headers: { "Accept" => "application/json", ... },
18
19
  basic_auth: { username: 'person', password: '1234' },
19
20
  timeout: 5,
20
21
  ... # Refer to https://github.com/jnunemaker/httparty/blob/master/lib/httparty.rb#L45
data/bin/siren_cli CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'byebug' if RUBY_VERSION > '2'
3
+ require 'byebug' if RUBY_VERSION > '2' && RUBY_PLATFORM != "java"
4
4
  require 'siren_cli'
5
5
 
6
6
  SirenCLI::Shell.new
@@ -2,12 +2,12 @@ module SirenClient
2
2
  class Entity
3
3
  include Enumerable
4
4
  attr_accessor :href
5
- attr_reader :payload, :classes, :properties, :entities, :rels,
5
+ attr_reader :payload, :classes, :properties, :entities, :rels,
6
6
  :links, :actions, :title, :type, :config
7
7
 
8
8
 
9
9
  def initialize(data, config={})
10
- @config = { format: :json }.merge config
10
+ @config = { format: :json }.merge config
11
11
  if data.class == String
12
12
  unless data.class == String && data.length > 0
13
13
  raise InvalidURIError, 'An invalid url was passed to SirenClient::Entity.new.'
@@ -42,8 +42,8 @@ module SirenClient
42
42
  return false unless criteria
43
43
  if criteria.is_a? String
44
44
  return entities.select do |ent|
45
- true if ent.classes.include?(criteria) ||
46
- ent.rels.include?(criteria) ||
45
+ true if ent.classes.include?(criteria) ||
46
+ ent.rels.include?(criteria) ||
47
47
  ent.href == criteria
48
48
  end
49
49
  elsif criteria.is_a? Regexp
@@ -60,7 +60,7 @@ module SirenClient
60
60
  return if self.href.empty?
61
61
  self.class.new(self.href, @config)
62
62
  end
63
-
63
+
64
64
  def method_missing(method, *args)
65
65
  method_str = method.to_s
66
66
  return @entities.length if method_str == 'length'
@@ -68,9 +68,9 @@ module SirenClient
68
68
  @properties.each do |key, prop|
69
69
  return prop if method_str == key
70
70
  end
71
- # Does it match an entity sub-link's class?
71
+ # Does it match an entity sub-link's class?
72
72
  @entities.each do |ent|
73
- return ent.go if ent.href &&
73
+ return ent.go if ent.href &&
74
74
  (ent.classes.map { |c| c.underscore }).include?(method_str.underscore)
75
75
  end
76
76
  # Does it match a link, if so traverse it and return the entity.
@@ -81,7 +81,7 @@ module SirenClient
81
81
  @actions.each do |key, action|
82
82
  return action if method_str == key.underscore
83
83
  end
84
- raise NoMethodError, 'The method does not match a property, action, or link on SirenClient::Entity.'
84
+ raise NoMethodError, "The method \"#{method_str}\" does not match a property, action, or link on SirenClient::Entity."
85
85
  end
86
86
 
87
87
  private
@@ -1,3 +1,3 @@
1
1
  module SirenClient
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/siren_client.gemspec CHANGED
@@ -25,7 +25,8 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "rake"
26
26
  spec.add_development_dependency "sinatra"
27
27
  spec.add_development_dependency "rspec"
28
- spec.add_development_dependency "byebug" if RUBY_VERSION > "2"
28
+ spec.add_development_dependency "byebug" if RUBY_VERSION > "2" && RUBY_PLATFORM != "java"
29
29
  spec.add_development_dependency "guard"
30
30
  spec.add_development_dependency "guard-rspec"
31
+ spec.add_development_dependency "coveralls"
31
32
  end
@@ -1,5 +1,7 @@
1
- require 'byebug' if RUBY_VERSION > '2'
1
+ require 'byebug' if RUBY_VERSION > '2' && RUBY_PLATFORM != "java"
2
2
  require 'siren_client'
3
+ require 'coveralls'
4
+ Coveralls.wear!
3
5
 
4
6
  RSpec.configure do |config|
5
7
  # Ensure we only use `expect` and not `should`.
@@ -26,24 +28,24 @@ def siren_body
26
28
  {
27
29
  'class' => ['messages', 'collection'],
28
30
  'rel' => ['/rels/messages'],
29
- 'href' => '/graphs/test1/messages'
31
+ 'href' => 'http://localhost/graphs/test1/messages'
30
32
  },
31
33
  {
32
34
  'class' => ['concepts', 'collection'],
33
35
  'rel' => ['/rels/concepts'],
34
- 'href' => '/graphs/test2/concepts'
36
+ 'href' => 'http://localhost/graphs/test2/concepts'
35
37
  },
36
38
  {
37
39
  # Just to test the underscore transformation
38
40
  'class' => ['user-preferences', 'collection'],
39
41
  'rel' => ['/rels/user-preferences'],
40
- 'href' => '/graphs/user/preferences'
42
+ 'href' => 'http://localhost/graphs/user/preferences'
41
43
  }
42
44
  ],
43
45
  'links' => [
44
46
  {
45
47
  'rel' => ['self'],
46
- 'href' => '/graphs/test1'
48
+ 'href' => 'http://localhost/graphs/test1'
47
49
  }
48
50
  ]
49
51
  }
@@ -52,7 +54,7 @@ def siren_body
52
54
  {
53
55
  'name' => 'filter_concepts',
54
56
  'method' => 'GET',
55
- 'href' => '/graphs/test1/concepts',
57
+ 'href' => 'http://localhost/graphs/test1/concepts',
56
58
  'title' => 'Get an optionally filtered list of Concepts',
57
59
  'type' => 'application/x-www-form-urlencoded',
58
60
  'fields' => [
@@ -79,7 +81,7 @@ def siren_body
79
81
  {
80
82
  'name' => 'filter-messages',
81
83
  'method' => 'GET',
82
- 'href' => '/graphs/test1/messages',
84
+ 'href' => 'http://localhost/graphs/test1/messages',
83
85
  'title' => 'Get an optionally filtered list of Messages',
84
86
  'type' => 'application/x-www-form-urlencoded',
85
87
  'fields' => [
@@ -107,15 +109,15 @@ def siren_body
107
109
  'links' => [
108
110
  {
109
111
  'rel' => ['self'],
110
- 'href' => '/graphs?limit=1&page=1&order_by=name'
112
+ 'href' => 'http://localhost/graphs?limit=1&page=1&order_by=name'
111
113
  },
112
114
  {
113
115
  'rel' => ['prev-page'],
114
- 'href' => '/graphs?limit=1&page=0&order_by=name'
116
+ 'href' => 'http://localhost/graphs?limit=1&page=0&order_by=name'
115
117
  },
116
118
  {
117
119
  'rel' => ['next'],
118
- 'href' => '/graphs?limit=1&page=2&order_by=name'
120
+ 'href' => 'http://localhost/graphs?limit=1&page=2&order_by=name'
119
121
  }
120
122
  ]
121
123
  }
@@ -83,7 +83,7 @@ describe SirenClient::Action do
83
83
  describe '.where(params)' do
84
84
  it 'executes the action without any parameters' do
85
85
  # I'm expecting an error here, all I want to see is that the url it being traversed.
86
- expect { action.where }.to raise_error
86
+ expect { action.where }.to raise_error SirenClient::InvalidResponseError
87
87
  end
88
88
  # The rest will be tested in the live specs.
89
89
  end
@@ -29,7 +29,7 @@ describe SirenClient do
29
29
  end
30
30
  describe '.logger=' do
31
31
  it 'raise an error if it does not respect the logger interface' do
32
- expect { SirenClient.logger = "error" }.to raise_error
32
+ expect { SirenClient.logger = "error" }.to raise_error SirenClient::InvalidLogger
33
33
  end
34
34
  it 'accepts an instance that respects the logger interface' do
35
35
  SirenClient.logger = Logger.new(STDOUT)
@@ -1,7 +1,7 @@
1
1
  require 'helper/spec_helper'
2
2
 
3
3
  describe SirenClient::Entity do
4
-
4
+
5
5
  describe '.new(data)' do
6
6
  it 'raise an error if no param is provided' do
7
7
  expect { SirenClient::Entity.new }.to raise_error(ArgumentError)
@@ -15,17 +15,14 @@ describe SirenClient::Entity do
15
15
  it 'raise an error if the url does not return json' do
16
16
  expect { SirenClient::Entity.new('http://www.google.com') }.to raise_error(SirenClient::InvalidResponseError)
17
17
  end
18
- # it 'can be instanciated with a proper url' do
19
- # expect(SirenClient::Entity.new(valid_url)).to be_a SirenClient::Entity
20
- # end
21
- it 'can be instanciated with a hash of data' do
18
+ it 'can be instanciated with a hash of data' do
22
19
  expect(SirenClient::Entity.new(siren_body)).to be_a SirenClient::Entity
23
20
  end
24
21
  end
25
22
 
26
- let (:entity) {
27
- SirenClient::Entity.new(siren_body, {
28
- headers: { "Accept" => "application/json" }
23
+ let (:entity) {
24
+ SirenClient::Entity.new(siren_body, {
25
+ headers: { "Accept" => "application/json" }
29
26
  })
30
27
  }
31
28
  describe '.config' do
@@ -117,29 +114,36 @@ describe SirenClient::Entity do
117
114
  expect(/query=test/).to match(entity.href)
118
115
  end
119
116
  end
120
- # Similar to SirenClient::Link.go this function will create a
117
+ # Similar to SirenClient::Link.go this function will create a
121
118
  # new entity from the .href method. For entity sub-links only.
122
119
  describe '.go' do
123
- let (:graph) { entity[0] }
120
+ let (:graph) { entity[0] }
124
121
  it 'return nil if it\'s NOT an entity sub-link' do
125
122
  expect(entity.go).to eq(nil)
126
123
  end
127
124
  it 'initiate a request if it IS an entity sub-link' do
128
- expect { graph.entities[0].go }.to raise_error
125
+ expect { graph.entities[0].go }.to raise_error Errno::ECONNREFUSED
129
126
  end
130
127
  end
131
128
  describe '.invalidkey' do
132
129
  it 'will throw a NoMethodError' do
133
130
  expect { entity.thisdoesntexist }.to raise_error(NoMethodError)
134
131
  end
132
+ it 'prints .invalidkey used to NoMethodError message' do
133
+ begin
134
+ entity.thisdoesntexist
135
+ rescue NoMethodError => e
136
+ expect( e.to_s ).to match(/thisdoesntexist/)
137
+ end
138
+ end
135
139
  end
136
140
  describe '.validkey' do
137
- let (:graph) { entity[0] }
141
+ let (:graph) { entity[0] }
138
142
  it 'can access an entity sub-link within the entity' do
139
- expect { graph.messages }.to raise_error
143
+ expect { graph.messages }.to raise_error Errno::ECONNREFUSED
140
144
  end
141
145
  it 'can access a link directly on the entity' do
142
- expect { entity.next }.to raise_error
146
+ expect { entity.next }.to raise_error Errno::ECONNREFUSED
143
147
  end
144
148
  it 'can access an action directly on the entity' do
145
149
  expect(entity.filter_concepts).to be_a SirenClient::Action
@@ -171,7 +175,7 @@ describe SirenClient::Entity do
171
175
  expect(entity[0]).to be_a SirenClient::Entity
172
176
  end
173
177
  end
174
- let (:graph) { entity[0] }
178
+ let (:graph) { entity[0] }
175
179
  describe '.search("messages")' do
176
180
  it 'returns an Array' do
177
181
  expect(graph.search('messages')).to be_a Array
@@ -217,14 +221,14 @@ describe SirenClient::Entity do
217
221
  describe 'underscore support' do
218
222
  it 'can access entity sub-links' do
219
223
  # Since this will trigger the sub-link. We expect an error
220
- expect { graph.user_preferences }.to raise_error
224
+ expect { graph.user_preferences }.to raise_error Errno::ECONNREFUSED
221
225
  end
222
226
  it 'can access actions' do
223
227
  expect(entity.filter_messages).to be_a SirenClient::Action
224
228
  end
225
229
  it 'can access links' do
226
230
  # Since this will trigger the link. We expect an error
227
- expect { entity.prev_page }.to raise_error
231
+ expect { entity.prev_page }.to raise_error Errno::ECONNREFUSED
228
232
  end
229
233
  end
230
234
  # Entities enumerable support
@@ -239,7 +243,7 @@ describe SirenClient::Entity do
239
243
  end
240
244
  end
241
245
  # Useful enumerable methods
242
- describe '.all?' do
246
+ describe '.all?' do
243
247
  it 'matches .entities.all?' do
244
248
  expect(
245
249
  graph.all? do |ent|
@@ -283,19 +287,6 @@ describe SirenClient::Entity do
283
287
  expect(graph.first).to eq(graph.entities.first)
284
288
  end
285
289
  end
286
- describe '.grep' do
287
- it "matches .entities.grep" do
288
- expect(
289
- graph.grep(/test1/) do |ent|
290
- ent.href
291
- end
292
- ).to eq(
293
- graph.entities.grep(/test1/) do |ent|
294
- ent.href
295
- end
296
- )
297
- end
298
- end
299
290
  describe '.map' do
300
291
  it 'matches .entities.map' do
301
292
  expect(
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chason Choate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-16 00:00:00.000000000 Z
11
+ date: 2016-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: coveralls
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  description: SirenClient provides an ActiveRecord-like syntax to traverse Siren APIs.
154
168
  email:
155
169
  - cha55son@gmail.com
@@ -209,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
223
  version: '0'
210
224
  requirements: []
211
225
  rubyforge_project:
212
- rubygems_version: 2.2.2
226
+ rubygems_version: 2.5.1
213
227
  signing_key:
214
228
  specification_version: 4
215
229
  summary: A client to traverse Siren APIs https://github.com/kevinswiber/siren