springboard-retail 4.1.1 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6d9770a0c5bb9a5076f573cace057df69eb35278
4
- data.tar.gz: 1688bf41e05ac367c0c331df7615a44449c59048
2
+ SHA256:
3
+ metadata.gz: 13eaf04ac55ef152f9c444f235656ad9899634d173aff26f6d87d287d9c07b94
4
+ data.tar.gz: ec8edecf083f85ce0750ba307080a00044daff4020acd8defd2ef6ce50ea45f2
5
5
  SHA512:
6
- metadata.gz: bc11ebe786dbda84a438fba1b21ff38fe4b4d03da694eb078df9d88e5ca986eea4e570369ba656b2115639c210d8971a7d4a19a8bd347cebac3a8caee08465d1
7
- data.tar.gz: 3dea0c75be77495585c9476cd9b04eaf6ff1aa86bdf2ff13aef27450443f6fdfcad92a2c43a6a328768a3a9dfc1ab2f31bcd6fcb69a275d1aa93b42f6a2c9b9a
6
+ metadata.gz: 158b90cf3fe6e854ec8aaa1ca77d503e7b43e3ce7aa106ad832bb5e85e3b6cde8712f6981d6f49827605d1fa636ed7dfb271edd32de805dac2deeac10412bf6d
7
+ data.tar.gz: 00e9ce7b716561a0994c06e2f8c78159f68346999f063cad57f9fb11ab2e1e5a1b66cef00849a5ee34950156ee81d1c6b37c287988783ba7a73cc2fcb7991d3a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- springboard-retail (4.1.1)
4
+ springboard-retail (4.2.0)
5
5
  addressable (~> 2.2.8)
6
6
  hashie
7
7
  json (>= 1.7.4)
@@ -24,8 +24,8 @@ GEM
24
24
  safe_yaml (~> 1.0.0)
25
25
  diff-lcs (1.2.5)
26
26
  docile (1.1.5)
27
- hashie (3.5.5)
28
- json (2.0.3)
27
+ hashie (3.5.7)
28
+ json (2.1.0)
29
29
  method_source (0.8.2)
30
30
  mime-types (2.4.3)
31
31
  multi_json (1.11.0)
@@ -80,4 +80,4 @@ DEPENDENCIES
80
80
  webmock
81
81
 
82
82
  BUNDLED WITH
83
- 1.14.4
83
+ 1.16.2
data/README.md CHANGED
@@ -103,6 +103,19 @@ resource.sort(:description, :created_at).filter(:active => true).each do |item|
103
103
  end
104
104
  ```
105
105
 
106
+ ### Returning select fields
107
+ Resources have a `only` method that accepts any number of field keys to return only the selected fields. Note that each call to `only` overwrites any previous fields.
108
+
109
+ ```ruby
110
+ resource.only(:id)
111
+ resource.only(:public_id, :updated_at)
112
+
113
+ # returns a new resource for chaining:
114
+ resource.only(:public_id, :updated_at).filter(:active => true).each do |item|
115
+ # ...
116
+ end
117
+ ```
118
+
106
119
  ### Creating Resources
107
120
 
108
121
  Create a new resource via POST:
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'patron'
3
- require 'addressable/uri'
4
3
  require 'json'
5
4
 
6
5
  require 'springboard/client/errors'
@@ -18,10 +17,6 @@ module Springboard
18
17
  # Provides direct access to the URI-oriented interface via the HTTP methods.
19
18
  # Provides access to the URI-oriented interface via the {#[]} method.
20
19
  class Client
21
- ##
22
- # Alias for {Addressable::URI}
23
- URI = Addressable::URI
24
-
25
20
  ##
26
21
  # Default number of records per page when iterating over collection resources
27
22
  DEFAULT_PER_PAGE = 20
@@ -85,7 +80,7 @@ module Springboard
85
80
  unless opts[:username] && opts[:password]
86
81
  raise "Must specify :username and :password"
87
82
  end
88
- body = URI.form_encode \
83
+ body = ::Addressable::URI.form_encode \
89
84
  :auth_key => opts[:username],
90
85
  :password => opts[:password]
91
86
  response = post '/auth/identity/callback', body,
@@ -265,4 +260,4 @@ end
265
260
  require 'springboard/client/resource'
266
261
  require 'springboard/client/response'
267
262
  require 'springboard/client/body'
268
- require 'springboard/client/uri_ext'
263
+ require 'springboard/client/uri'
@@ -79,6 +79,19 @@ module Springboard
79
79
  query('sort' => sorts)
80
80
  end
81
81
 
82
+ ##
83
+ # Returns a new resource with the given fields added to the query string as _only parameters.
84
+ #
85
+ # @example
86
+ # resource.only('id', :public_id)
87
+ #
88
+ # @param [#to_s] returns One or more fields
89
+ #
90
+ # @return [Resource]
91
+ def only(*fields)
92
+ query('_only' => fields)
93
+ end
94
+
82
95
  ##
83
96
  # Performs a request to get the first result of the first page of the
84
97
  # collection and returns it.
@@ -0,0 +1,96 @@
1
+ require 'addressable/uri'
2
+
3
+ module Springboard
4
+ class Client
5
+ ##
6
+ # A wrapper around Addressable::URI
7
+ class URI
8
+ ##
9
+ # Returns a URI object based on the parsed string.
10
+ #
11
+ # @return [URI]
12
+ def self.parse(value)
13
+ return value if value.is_a?(self)
14
+ new(::Addressable::URI.parse(value))
15
+ end
16
+
17
+ ##
18
+ # Joins several URIs together.
19
+ #
20
+ # @return [URI]
21
+ def self.join(*args)
22
+ new(::Addressable::URI.join(*args))
23
+ end
24
+
25
+ ##
26
+ # Creates a new URI object from an Addressable::URI
27
+ #
28
+ # @return [URI]
29
+ def initialize(uri)
30
+ @uri = uri
31
+ end
32
+
33
+ ##
34
+ # Returns a new URI with the given subpath appended to it. Ensures a single
35
+ # forward slash between the URI's path and the given subpath.
36
+ #
37
+ # @return [URI]
38
+ def subpath(subpath)
39
+ uri = dup
40
+ uri.path = "#{path}/" unless path.end_with?('/')
41
+ uri.join subpath.to_s.gsub(/^\//, '')
42
+ end
43
+
44
+ ##
45
+ # Merges the given hash of query string parameters and values with the URI's
46
+ # existing query string parameters (if any).
47
+ def merge_query_values!(values)
48
+ self.springboard_query_values = (self.query_values || {}).merge(normalize_query_hash(values))
49
+ end
50
+
51
+ def ==(other_uri)
52
+ return false unless other_uri.is_a?(self.class)
53
+ uri == other_uri.__send__(:uri)
54
+ end
55
+
56
+ private
57
+
58
+ attr_reader :uri
59
+
60
+ def springboard_query_values=(values)
61
+ retval = self.query_values = normalize_query_hash(values)
62
+ # Hack to strip digits from Addressable::URI's subscript notation
63
+ self.query = self.query.gsub(/\[\d+\]=/, '[]=')
64
+ retval
65
+ end
66
+
67
+ def self.delegate_and_wrap(*methods)
68
+ methods.each do |method|
69
+ define_method(method) do |*args, &block|
70
+ result = @uri.__send__(method, *args, &block)
71
+ if result.is_a?(Addressable::URI)
72
+ self.class.new(result)
73
+ else
74
+ result
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ delegate_and_wrap(
81
+ :join, :path, :path=, :form_encode, :to_s,
82
+ :query_values, :query_values=, :query, :query=
83
+ )
84
+
85
+ def normalize_query_hash(hash)
86
+ hash.inject({}) do |copy, (k, v)|
87
+ copy[k.to_s] = case v
88
+ when Hash then normalize_query_hash(v)
89
+ when true, false then v.to_s
90
+ else v end
91
+ copy
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -5,8 +5,13 @@ require 'springboard-retail'
5
5
  require 'webmock/rspec'
6
6
  require 'shared_client_context'
7
7
 
8
+ RSpec.configure do |c|
9
+ c.filter_run :focus => true
10
+ c.run_all_when_everything_filtered = true
11
+ end
12
+
8
13
  class String
9
14
  def to_uri
10
- Addressable::URI.parse(self)
15
+ Springboard::Client::URI.parse(self)
11
16
  end
12
17
  end
@@ -97,6 +97,16 @@ describe Springboard::Client::Resource do
97
97
  end
98
98
  end
99
99
 
100
+ describe "only" do
101
+ it "should set the _only parameter based on the given values" do
102
+ expect(resource.only('f1', 'f2').uri.query).to eq('_only[]=f1&_only[]=f2')
103
+ end
104
+
105
+ it "should replace the existing _only parameters" do
106
+ expect(resource.only('f1').only('f2', 'f3').uri.query).to eq('_only[]=f2&_only[]=f3')
107
+ end
108
+ end
109
+
100
110
  %w{count each each_page}.each do |method|
101
111
  describe method do
102
112
  it "should call the client's #{method} method with the resource's URI" do
@@ -1,13 +1,42 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Addressable::URI do
4
- let(:uri) { Addressable::URI.parse('/relative/path') }
3
+ describe Springboard::Client::URI do
4
+ let(:uri) { described_class.parse('/relative/path') }
5
5
 
6
6
  describe "subpath" do
7
7
  it "should return a new URI with the path relative to the receiver" do
8
- expect(uri.subpath('other')).to eq(Addressable::URI.parse('/relative/path/other'))
9
- expect(uri.subpath('/other')).to eq(Addressable::URI.parse('/relative/path/other'))
10
- uri.subpath(Addressable::URI.parse('/other')) == Addressable::URI.parse('/relative/path/other')
8
+ expect(uri.subpath('other')).to eq(described_class.parse('/relative/path/other'))
9
+ expect(uri.subpath('/other')).to eq(described_class.parse('/relative/path/other'))
10
+ uri.subpath(described_class.parse('/other')) == described_class.parse('/relative/path/other')
11
+ end
12
+ end
13
+
14
+ describe "parse" do
15
+ it "should return a URI based on the given string" do
16
+ uri = described_class.parse('/some_path')
17
+ expect(uri).to be_a(described_class)
18
+ expect(uri.to_s).to eq('/some_path')
19
+ end
20
+ end
21
+
22
+ describe "==" do
23
+ it "should consider two URIs parsed from the same string equal" do
24
+ expect(
25
+ described_class.parse('http://example.com/some_path?a=1&b=2') ==
26
+ described_class.parse('http://example.com/some_path?a=1&b=2')
27
+ ).to be(true)
28
+ end
29
+
30
+ it "should consider two URIs parsed from different strings not equal" do
31
+ expect(
32
+ described_class.parse('http://example.com/some_path?a=1&b=2') ==
33
+ described_class.parse('http://example.com/some_path?a=1&c=3')
34
+ ).to be(false)
35
+
36
+ expect(
37
+ described_class.parse('http://foo.example.com') ==
38
+ described_class.parse('http://bar.example.com')
39
+ ).to be(false)
11
40
  end
12
41
  end
13
42
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'springboard-retail'
3
- s.version = '4.1.1'
3
+ s.version = '4.2.0'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ['Jay Stotz']
6
6
  s.summary = 'Springboard Retail API client library'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: springboard-retail
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.1
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Stotz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-01 00:00:00.000000000 Z
11
+ date: 2018-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: patron
@@ -88,13 +88,13 @@ files:
88
88
  - lib/springboard/client/errors.rb
89
89
  - lib/springboard/client/resource.rb
90
90
  - lib/springboard/client/response.rb
91
- - lib/springboard/client/uri_ext.rb
91
+ - lib/springboard/client/uri.rb
92
92
  - spec/shared_client_context.rb
93
93
  - spec/spec_helper.rb
94
94
  - spec/springboard/client/body_spec.rb
95
95
  - spec/springboard/client/resource_spec.rb
96
96
  - spec/springboard/client/response_spec.rb
97
- - spec/springboard/client/uri_ext_spec.rb
97
+ - spec/springboard/client/uri_spec.rb
98
98
  - spec/springboard/client_spec.rb
99
99
  - springboard-retail.gemspec
100
100
  - vendor/cache/addressable-2.2.8.gem
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  version: 1.3.6
147
147
  requirements: []
148
148
  rubyforge_project:
149
- rubygems_version: 2.5.2
149
+ rubygems_version: 2.7.6
150
150
  signing_key:
151
151
  specification_version: 4
152
152
  summary: Springboard Retail API client library
@@ -1,51 +0,0 @@
1
- module Springboard
2
- class Client
3
- ##
4
- # Extensions to the Addressable::URI class.
5
- module URIExt
6
- ##
7
- # Returns a new URI with the given subpath appended to it. Ensures a single
8
- # forward slash between the URI's path and the given subpath.
9
- def subpath(subpath)
10
- uri = dup
11
- uri.path = "#{path}/" unless path.end_with?('/')
12
- uri.join subpath.to_s.gsub(/^\//, '')
13
- end
14
-
15
- ##
16
- # Merges the given hash of query string parameters and values with the URI's
17
- # existing query string parameters (if any).
18
- def merge_query_values!(values)
19
- self.springboard_query_values = (self.query_values || {}).merge(normalize_query_hash(values))
20
- end
21
-
22
- private
23
-
24
- def springboard_query_values=(values)
25
- retval = self.query_values = normalize_query_hash(values)
26
- # Hack to strip digits from Addressable::URI's subscript notation
27
- self.query = self.query.gsub(/\[\d+\]=/, '[]=')
28
- retval
29
- end
30
-
31
- def normalize_query_hash(hash)
32
- hash.inject({}) do |copy, (k, v)|
33
- copy[k.to_s] = case v
34
- when Hash then normalize_query_hash(v)
35
- when true, false then v.to_s
36
- else v end
37
- copy
38
- end
39
- end
40
- end
41
- end
42
- end
43
-
44
- ##
45
- # We include Springboard::Client::URIExt into Addressable::URI because its design
46
- # doesn't support subclassing.
47
- #
48
- # @see http://addressable.rubyforge.org/api/Addressable/URI.html Addressable::URI docs
49
- class Addressable::URI
50
- include Springboard::Client::URIExt
51
- end