chartmogul_client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chartmogul/v1/customers.rb +30 -12
- data/lib/chartmogul/v1/request.rb +9 -5
- data/lib/chartmogul/version.rb +1 -1
- data/spec/chartmogul/v1/customers_spec.rb +8 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a086af54516adf8632da52a59d11cffe99358699
|
4
|
+
data.tar.gz: e7bb8210daa809b122fb81b1126777cfec9ae437
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ef2be6f7435ebb4f9f092516a3d5cb4a17efba117ec9cf3d5898b1b91e92ea69febe30ccb6e4def912e749327e2bf6249158a6b54ae7c040c43524d69fd2b1a
|
7
|
+
data.tar.gz: 9942371b93de9d5a75fca0f9419908b78fa8d308f0a2975b464c4abecde8be34d3ca5316191f271ef2567a6eb6a643899fbab647494d2431998dce31b36bd375
|
@@ -17,17 +17,23 @@ module Chartmogul
|
|
17
17
|
#
|
18
18
|
# customer_id - The String/Integer ChartMogul ID of the customer.
|
19
19
|
# Specified as part of the URL.
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
20
|
+
# attributes - The Array options used to create a Attributes (default: []).
|
21
|
+
#
|
22
|
+
# Examples
|
23
|
+
#
|
24
|
+
# client.customers.attributes.create 'foo', [
|
25
|
+
# { type: 'String', key: 'bar', value: 'baz' },
|
26
|
+
# { type: 'Integer', key: 'qux', value: 1 }
|
27
|
+
# ]
|
27
28
|
#
|
28
29
|
# Returns the instance of Chartmogul::V1::Request.
|
29
|
-
def create(customer_id,
|
30
|
-
Chartmogul::V1::Request.new
|
30
|
+
def create(customer_id, attributes = [])
|
31
|
+
Chartmogul::V1::Request.new("#{BASE_URI}/#{customer_id}/attributes/custom",
|
32
|
+
body: MultiJson.dump(custom: attributes),
|
33
|
+
headers: { 'Content-Type' => 'application/json' },
|
34
|
+
method: :post,
|
35
|
+
userpwd: client.userpwd,
|
36
|
+
)
|
31
37
|
end
|
32
38
|
|
33
39
|
# Public: Update Custom Attributes of a Customer.
|
@@ -36,11 +42,23 @@ module Chartmogul
|
|
36
42
|
#
|
37
43
|
# customer_id - The String/Integer ChartMogul ID of the customer.
|
38
44
|
# Specified as part of the URL.
|
39
|
-
#
|
45
|
+
# attributes - The Array options used to refine the Customer attributes (default: []).
|
46
|
+
#
|
47
|
+
# Examples
|
48
|
+
#
|
49
|
+
# client.customers.attributes.update 'foo', [
|
50
|
+
# { type: 'String', key: 'bar', value: 'baz' },
|
51
|
+
# { type: 'Integer', key: 'qux', value: 1 }
|
52
|
+
# ]
|
40
53
|
#
|
41
54
|
# Returns the instance of Chartmogul::V1::Request.
|
42
|
-
def update(customer_id,
|
43
|
-
Chartmogul::V1::Request.new
|
55
|
+
def update(customer_id, attributes = [])
|
56
|
+
Chartmogul::V1::Request.new("#{BASE_URI}/#{customer_id}/attributes/custom",
|
57
|
+
body: MultiJson.dump(custom: attributes),
|
58
|
+
headers: { 'Content-Type' => 'application/json' },
|
59
|
+
method: :put,
|
60
|
+
userpwd: client.userpwd,
|
61
|
+
)
|
44
62
|
end
|
45
63
|
end
|
46
64
|
|
@@ -10,19 +10,23 @@ module Chartmogul
|
|
10
10
|
# Public: Constructor.
|
11
11
|
#
|
12
12
|
# url - The String url.
|
13
|
-
#
|
13
|
+
# body - The String body.
|
14
|
+
# headers - The Hash headers.
|
14
15
|
# method - The Symbol request method (default: :get).
|
16
|
+
# userpwd - The String with credentials for Basic Authentication.
|
15
17
|
# params - The Hash query params.
|
16
|
-
def initialize(url,
|
18
|
+
def initialize(url, body: nil, headers: nil, method: :get, userpwd: nil, **params)
|
17
19
|
@url = url
|
18
20
|
@userpwd = userpwd
|
19
21
|
@params = params
|
20
22
|
@response = Typhoeus::Request.new(url,
|
21
|
-
|
23
|
+
body: body,
|
24
|
+
connecttimeout: 5,
|
25
|
+
headers: headers,
|
22
26
|
method: method,
|
23
27
|
params: params,
|
24
|
-
|
25
|
-
|
28
|
+
timeout: 10,
|
29
|
+
userpwd: userpwd,
|
26
30
|
).run
|
27
31
|
end
|
28
32
|
|
data/lib/chartmogul/version.rb
CHANGED
@@ -14,26 +14,28 @@ RSpec.describe Chartmogul::V1::Customers do
|
|
14
14
|
describe '::Attributes' do
|
15
15
|
describe '#create' do
|
16
16
|
let(:url) { 'https://api.chartmogul.com/v1/customers/customer-id/attributes/custom' }
|
17
|
-
let(:
|
17
|
+
let(:body) { [ {foo: 'bar'} ] }
|
18
|
+
let(:query) { {} }
|
18
19
|
|
19
20
|
before do
|
20
|
-
stub_request(:post, url).with(
|
21
|
+
stub_request(:post, url).with(body: { custom: body }.to_json).to_return(status: 200)
|
21
22
|
end
|
22
23
|
|
23
|
-
subject { client.customers.attributes.create('customer-id',
|
24
|
+
subject { client.customers.attributes.create('customer-id', body) }
|
24
25
|
|
25
26
|
it_should_behave_like 'a base ChartMogul API V1 requests', method: :post
|
26
27
|
end
|
27
28
|
|
28
29
|
describe '#update' do
|
29
30
|
let(:url) { 'https://api.chartmogul.com/v1/customers/customer-id/attributes/custom' }
|
30
|
-
let(:
|
31
|
+
let(:body) { [ {foo: 'bar'} ] }
|
32
|
+
let(:query) { {} }
|
31
33
|
|
32
34
|
before do
|
33
|
-
stub_request(:put, url).with(
|
35
|
+
stub_request(:put, url).with(body: { custom: body }.to_json).to_return(status: 200)
|
34
36
|
end
|
35
37
|
|
36
|
-
subject { client.customers.attributes.update('customer-id',
|
38
|
+
subject { client.customers.attributes.update('customer-id', body) }
|
37
39
|
|
38
40
|
it_should_behave_like 'a base ChartMogul API V1 requests', method: :put
|
39
41
|
end
|