ecwid_api 0.0.2 → 0.1.0
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/.travis.yml +8 -0
- data/Gemfile +2 -0
- data/README.md +228 -144
- data/ecwid_api.gemspec +1 -0
- data/lib/ecwid_api/api/base.rb +17 -0
- data/lib/ecwid_api/api/categories.rb +57 -0
- data/lib/ecwid_api/api/orders.rb +36 -0
- data/lib/ecwid_api/api/product_combinations.rb +51 -0
- data/lib/ecwid_api/api/products.rb +64 -0
- data/lib/ecwid_api/api.rb +31 -0
- data/lib/ecwid_api/category.rb +59 -4
- data/lib/ecwid_api/client.rb +65 -94
- data/lib/ecwid_api/entity.rb +138 -26
- data/lib/ecwid_api/error.rb +12 -2
- data/lib/ecwid_api/o_auth.rb +106 -0
- data/lib/ecwid_api/order.rb +82 -0
- data/lib/ecwid_api/order_item.rb +17 -0
- data/lib/ecwid_api/paged_ecwid_response.rb +55 -0
- data/lib/ecwid_api/paged_enumerator.rb +66 -0
- data/lib/ecwid_api/person.rb +7 -0
- data/lib/ecwid_api/product.rb +77 -0
- data/lib/ecwid_api/product_combination.rb +34 -0
- data/lib/ecwid_api/version.rb +1 -1
- data/lib/ecwid_api.rb +25 -39
- data/lib/ext/string.rb +12 -4
- data/spec/api/categories_spec.rb +31 -0
- data/spec/api/orders_spec.rb +30 -0
- data/spec/api/products_spec.rb +20 -0
- data/spec/category_spec.rb +33 -38
- data/spec/client_spec.rb +20 -48
- data/spec/entity_spec.rb +90 -5
- data/spec/fixtures/categories.json +28 -22
- data/spec/fixtures/order.json +162 -0
- data/spec/fixtures/orders.json +302 -0
- data/spec/fixtures/products.json +141 -0
- data/spec/helpers/client.rb +32 -0
- data/spec/oauth_spec.rb +40 -0
- data/spec/order_item_spec.rb +12 -0
- data/spec/order_spec.rb +71 -0
- data/spec/paged_enumerator_spec.rb +38 -0
- data/spec/spec_helper.rb +24 -23
- metadata +53 -9
- data/lib/ecwid_api/category_api.rb +0 -62
- data/spec/category_api_spec.rb +0 -36
- data/spec/ecwid_api_spec.rb +0 -15
- data/spec/helpers/faraday.rb +0 -30
@@ -0,0 +1,32 @@
|
|
1
|
+
module Helpers
|
2
|
+
module Client
|
3
|
+
def client
|
4
|
+
@client ||= EcwidApi::Client.new(12345, "access_token").tap do |client|
|
5
|
+
allow(client).to receive(:connection).and_return(faraday)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def fixtures
|
10
|
+
%w(categories category orders products)
|
11
|
+
end
|
12
|
+
|
13
|
+
def faraday_stubs
|
14
|
+
::Faraday::Adapter::Test::Stubs.new do |stub|
|
15
|
+
fixtures.each do |fixture|
|
16
|
+
stub.get(fixture) { [ 200, {"Content-Type" => "application/json"}, File.read("spec/fixtures/#{fixture}.json") ] }
|
17
|
+
end
|
18
|
+
stub.get("/categories/5") { [200, {"Content-Type" => "application/json"}, File.read("spec/fixtures/category.json") ] }
|
19
|
+
stub.get("/orders/35") { [200, {"Content-Type" => "application/json"}, File.read("spec/fixtures/order.json") ] }
|
20
|
+
stub.get("/orders/404") { [404, {"Content-Type" => "application/json"}, nil ] }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Public: Returns a test Faraday::Connection
|
25
|
+
def faraday
|
26
|
+
::Faraday.new do |builder|
|
27
|
+
builder.response :json, content_type: /\bjson$/
|
28
|
+
builder.adapter :test, faraday_stubs
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/oauth_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EcwidApi::OAuth do
|
4
|
+
subject do
|
5
|
+
EcwidApi::OAuth.new do |config|
|
6
|
+
config.client_id = "client_id"
|
7
|
+
config.client_secret = "client_secret"
|
8
|
+
config.scope = "scope"
|
9
|
+
config.redirect_uri = "https://example.com/oauth"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
its(:oauth_url) { should == "https://my.ecwid.com/api/oauth/authorize?client_id=client_id&scope=scope&response_type=code&redirect_uri=https%3A%2F%2Fexample.com%2Foauth" }
|
14
|
+
|
15
|
+
describe "#access_token(code)" do
|
16
|
+
let(:response) do
|
17
|
+
double("response").tap do |response|
|
18
|
+
allow(response).to receive(:success?).and_return(true)
|
19
|
+
allow(response).to receive(:body).and_return(access_token: "the_token", store_id: "12345")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
before(:each) do
|
24
|
+
allow(subject.send(:connection)).to receive(:post).with("/api/oauth/token", hash_including(code: "code")).and_return(response)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "sends a request to the API for an access_token" do
|
28
|
+
expect(subject.send(:connection)).to receive(:post).with("/api/oauth/token", hash_including(code: "code")).and_return(response)
|
29
|
+
subject.access_token("code")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns an object that has the access_token" do
|
33
|
+
subject.access_token("code").access_token.should == "the_token"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns an object that has the store_id" do
|
37
|
+
subject.access_token("code").store_id.should == "12345"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EcwidApi::OrderItem do
|
4
|
+
subject { EcwidApi::OrderItem.new({"sku" => "12345", "categoryId" => 222}, client: client) }
|
5
|
+
|
6
|
+
describe "#category" do
|
7
|
+
it "gets the category from the client" do
|
8
|
+
expect(client.categories).to receive(:find).with(222)
|
9
|
+
subject.category
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/order_spec.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EcwidApi::Order, faraday: true do
|
4
|
+
subject do
|
5
|
+
EcwidApi::Order.new({
|
6
|
+
"orderNumber" => 123,
|
7
|
+
"billingPerson" => {
|
8
|
+
"name" => "John Doe"
|
9
|
+
},
|
10
|
+
"shippingPerson" => shipping_person,
|
11
|
+
"items" => [{
|
12
|
+
"sku" => "112233"
|
13
|
+
}],
|
14
|
+
"fulfillmentStatus" => "AWAITING_PROCESSING"
|
15
|
+
})
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:shipping_person) { nil }
|
19
|
+
|
20
|
+
its(:id) { should == 123 }
|
21
|
+
|
22
|
+
describe "#billing_person" do
|
23
|
+
its(:billing_person) { should be_a(EcwidApi::Person) }
|
24
|
+
|
25
|
+
it "has the correct data" do
|
26
|
+
subject.billing_person.name.should == "John Doe"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#shipping_person" do
|
31
|
+
its(:shipping_person) { should be_a(EcwidApi::Person) }
|
32
|
+
|
33
|
+
context "without a shipping person" do
|
34
|
+
let(:shipping_person) { nil }
|
35
|
+
its(:shipping_person) { should == subject.billing_person }
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with a shipping person" do
|
39
|
+
let(:shipping_person) { {"name" => "Jane Doe"} }
|
40
|
+
it "has the correct data" do
|
41
|
+
subject.shipping_person.name.should == "Jane Doe"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#items" do
|
47
|
+
it "has the correct number of items" do
|
48
|
+
subject.items.size.should == 1
|
49
|
+
end
|
50
|
+
|
51
|
+
it "has the correct data" do
|
52
|
+
subject.items.first.sku.should == "112233"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#fulfillment_status=" do
|
57
|
+
it "raises an error with an invalid status" do
|
58
|
+
expect { subject.fulfillment_status = :stuff }.to raise_error
|
59
|
+
end
|
60
|
+
|
61
|
+
it "doesn't raise an error with a valid status" do
|
62
|
+
expect { subject.fulfillment_status = :processing }.to_not raise_error
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#fulfillment_status" do
|
67
|
+
it "is symbolized" do
|
68
|
+
subject.fulfillment_status.should == :awaiting_processing
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EcwidApi::PagedEnumerator do
|
4
|
+
subject do
|
5
|
+
EcwidApi::PagedEnumerator.new(response_one, &proc)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:proc) do
|
9
|
+
Proc.new do |response, yielder|
|
10
|
+
response[:stuff].each { |thing| yielder << thing }
|
11
|
+
response[:next]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:response_one) do
|
16
|
+
{
|
17
|
+
stuff: %w(1 2 3),
|
18
|
+
next: response_two
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:response_two) do
|
23
|
+
{
|
24
|
+
stuff: %w(4 5 6),
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
it "contains the whole result set" do
|
29
|
+
subject.to_a.should == %w(1 2 3 4 5 6)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "iterates over each response once" do
|
33
|
+
expect(response_two[:stuff]).to receive(:each).once.and_call_original
|
34
|
+
|
35
|
+
subject.each
|
36
|
+
subject.each
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,23 +1,24 @@
|
|
1
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
-
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
-
# loaded once.
|
5
|
-
#
|
6
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
-
|
8
|
-
require "ecwid_api"
|
9
|
-
require "helpers/
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
config.
|
14
|
-
config.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
|
23
|
-
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require "ecwid_api"
|
9
|
+
require "helpers/client"
|
10
|
+
require "pry"
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
config.filter_run :focus
|
16
|
+
|
17
|
+
config.include Helpers::Client
|
18
|
+
|
19
|
+
# Run specs in random order to surface order dependencies. If you find an
|
20
|
+
# order dependency and want to debug it, you can fix the order by providing
|
21
|
+
# the seed, which is printed after each run.
|
22
|
+
# --seed 1234
|
23
|
+
config.order = 'random'
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecwid_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Biehl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 2.14.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: faraday
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,27 +103,49 @@ extra_rdoc_files: []
|
|
89
103
|
files:
|
90
104
|
- .gitignore
|
91
105
|
- .rspec
|
106
|
+
- .travis.yml
|
92
107
|
- Gemfile
|
93
108
|
- LICENSE.txt
|
94
109
|
- README.md
|
95
110
|
- Rakefile
|
96
111
|
- ecwid_api.gemspec
|
97
112
|
- lib/ecwid_api.rb
|
113
|
+
- lib/ecwid_api/api.rb
|
114
|
+
- lib/ecwid_api/api/base.rb
|
115
|
+
- lib/ecwid_api/api/categories.rb
|
116
|
+
- lib/ecwid_api/api/orders.rb
|
117
|
+
- lib/ecwid_api/api/product_combinations.rb
|
118
|
+
- lib/ecwid_api/api/products.rb
|
98
119
|
- lib/ecwid_api/category.rb
|
99
|
-
- lib/ecwid_api/category_api.rb
|
100
120
|
- lib/ecwid_api/client.rb
|
101
121
|
- lib/ecwid_api/entity.rb
|
102
122
|
- lib/ecwid_api/error.rb
|
123
|
+
- lib/ecwid_api/o_auth.rb
|
124
|
+
- lib/ecwid_api/order.rb
|
125
|
+
- lib/ecwid_api/order_item.rb
|
126
|
+
- lib/ecwid_api/paged_ecwid_response.rb
|
127
|
+
- lib/ecwid_api/paged_enumerator.rb
|
128
|
+
- lib/ecwid_api/person.rb
|
129
|
+
- lib/ecwid_api/product.rb
|
130
|
+
- lib/ecwid_api/product_combination.rb
|
103
131
|
- lib/ecwid_api/version.rb
|
104
132
|
- lib/ext/string.rb
|
105
|
-
- spec/
|
133
|
+
- spec/api/categories_spec.rb
|
134
|
+
- spec/api/orders_spec.rb
|
135
|
+
- spec/api/products_spec.rb
|
106
136
|
- spec/category_spec.rb
|
107
137
|
- spec/client_spec.rb
|
108
|
-
- spec/ecwid_api_spec.rb
|
109
138
|
- spec/entity_spec.rb
|
110
139
|
- spec/fixtures/categories.json
|
111
140
|
- spec/fixtures/category.json
|
112
|
-
- spec/
|
141
|
+
- spec/fixtures/order.json
|
142
|
+
- spec/fixtures/orders.json
|
143
|
+
- spec/fixtures/products.json
|
144
|
+
- spec/helpers/client.rb
|
145
|
+
- spec/oauth_spec.rb
|
146
|
+
- spec/order_item_spec.rb
|
147
|
+
- spec/order_spec.rb
|
148
|
+
- spec/paged_enumerator_spec.rb
|
113
149
|
- spec/spec_helper.rb
|
114
150
|
homepage: ''
|
115
151
|
licenses:
|
@@ -136,12 +172,20 @@ signing_key:
|
|
136
172
|
specification_version: 4
|
137
173
|
summary: A client for the Ecwid REST API
|
138
174
|
test_files:
|
139
|
-
- spec/
|
175
|
+
- spec/api/categories_spec.rb
|
176
|
+
- spec/api/orders_spec.rb
|
177
|
+
- spec/api/products_spec.rb
|
140
178
|
- spec/category_spec.rb
|
141
179
|
- spec/client_spec.rb
|
142
|
-
- spec/ecwid_api_spec.rb
|
143
180
|
- spec/entity_spec.rb
|
144
181
|
- spec/fixtures/categories.json
|
145
182
|
- spec/fixtures/category.json
|
146
|
-
- spec/
|
183
|
+
- spec/fixtures/order.json
|
184
|
+
- spec/fixtures/orders.json
|
185
|
+
- spec/fixtures/products.json
|
186
|
+
- spec/helpers/client.rb
|
187
|
+
- spec/oauth_spec.rb
|
188
|
+
- spec/order_item_spec.rb
|
189
|
+
- spec/order_spec.rb
|
190
|
+
- spec/paged_enumerator_spec.rb
|
147
191
|
- spec/spec_helper.rb
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module EcwidApi
|
2
|
-
# Public: This is the Ecwid API for Categories. It abstracts the end-points
|
3
|
-
# of the Ecwid API that deal with categories.
|
4
|
-
class CategoryApi
|
5
|
-
# Private: Gets the Client
|
6
|
-
attr_reader :client
|
7
|
-
private :client
|
8
|
-
|
9
|
-
# Public: Initializes a new EcwidApi::CategoryApi
|
10
|
-
#
|
11
|
-
# client - The EcwidApi::Client to use with the API
|
12
|
-
#
|
13
|
-
def initialize(client = EcwidApi.default_client)
|
14
|
-
@client = client
|
15
|
-
raise Error.new("The client cannot be nil") unless client
|
16
|
-
end
|
17
|
-
|
18
|
-
# Public: Returns all of the sub-categories for a given category
|
19
|
-
#
|
20
|
-
# See: http://kb.ecwid.com/w/page/25285101/Product%20API#RESTAPIMethodcategories
|
21
|
-
#
|
22
|
-
# parent - The Category ID of the parent category. If the parent is 0 then
|
23
|
-
# a list of the root categories will be returned. If the parent is
|
24
|
-
# nil, then all of the categories will be returned
|
25
|
-
#
|
26
|
-
# Returns an array of EcwidApi::Category objects
|
27
|
-
def all(parent = nil)
|
28
|
-
params = {}
|
29
|
-
params[:parent] = parent if parent
|
30
|
-
|
31
|
-
response = client.get("categories", params)
|
32
|
-
|
33
|
-
if response.success?
|
34
|
-
response.body
|
35
|
-
else
|
36
|
-
[]
|
37
|
-
end.map {|category| Category.new(category, client: client) }
|
38
|
-
end
|
39
|
-
|
40
|
-
# Public: Returns an Array of the root level EcwidApi::Category objects
|
41
|
-
def root
|
42
|
-
all(0)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Public: Returns a single EcwidApi::Category
|
46
|
-
#
|
47
|
-
# See: http://kb.ecwid.com/w/page/25285101/Product%20API#RESTAPIMethodcategory
|
48
|
-
#
|
49
|
-
# category_id - A Category ID to get
|
50
|
-
#
|
51
|
-
# Returns an EcwidApi::Category, or nil if it can't be found
|
52
|
-
def find(category_id)
|
53
|
-
response = client.get("category", id: category_id)
|
54
|
-
|
55
|
-
if response.success?
|
56
|
-
Category.new(response.body, client: client)
|
57
|
-
else
|
58
|
-
nil
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
data/spec/category_api_spec.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe EcwidApi::CategoryApi, faraday: true do
|
4
|
-
let(:client) { EcwidApi::Client.new { |config| config.store_id = '12345' } }
|
5
|
-
subject { EcwidApi::CategoryApi.new(client) }
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
faraday_client(client)
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "#all" do
|
12
|
-
it "gets all of the categories from the client" do
|
13
|
-
expect(client).to receive(:get).with("categories", {}).and_call_original
|
14
|
-
subject.all
|
15
|
-
end
|
16
|
-
|
17
|
-
it "gets sub categories" do
|
18
|
-
expect(client).to receive(:get).with("categories", parent: 5).and_call_original
|
19
|
-
subject.all(5)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "#root" do
|
24
|
-
it "gets the root level categories" do
|
25
|
-
expect(subject).to receive(:all).with(0).and_call_original
|
26
|
-
subject.root
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "#find" do
|
31
|
-
it "finds a single category" do
|
32
|
-
expect(client).to receive(:get).with("category", id: 5).and_call_original
|
33
|
-
subject.find(5)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/spec/ecwid_api_spec.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe EcwidApi do
|
4
|
-
describe "::default_client" do
|
5
|
-
it "builds an EcwidApi::Client with the block" do
|
6
|
-
EcwidApi.default_client.should be_nil
|
7
|
-
|
8
|
-
client = EcwidApi.default_client do |config|
|
9
|
-
config.store_id = 123
|
10
|
-
end
|
11
|
-
|
12
|
-
client.is_a?(EcwidApi::Client).should be_true
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data/spec/helpers/faraday.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
|
3
|
-
module Helpers
|
4
|
-
module Faraday
|
5
|
-
def fixtures
|
6
|
-
%w(categories category)
|
7
|
-
end
|
8
|
-
|
9
|
-
def faraday_stubs
|
10
|
-
::Faraday::Adapter::Test::Stubs.new do |stub|
|
11
|
-
fixtures.each do |fixture|
|
12
|
-
stub.get(fixture) { [ 200, {"Content-Type" => "application/json"}, File.read("spec/fixtures/#{fixture}.json") ] }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# Public: Returns a test Faraday::Connection
|
18
|
-
def faraday
|
19
|
-
::Faraday.new do |builder|
|
20
|
-
builder.response :json, content_type: /\bjson$/
|
21
|
-
builder.adapter :test, faraday_stubs
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Public: Uses the Faraday stub connection with the client
|
26
|
-
def faraday_client(client)
|
27
|
-
allow(client).to receive(:connection).and_return(faraday)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|