chartmogul_client 0.0.2 → 0.0.3

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: 11dfe4c4cc311dbad2aae85865d08704cdcac56f
4
- data.tar.gz: 056f8a8441dee5682fd75e8b76743fd66b23097d
3
+ metadata.gz: a086af54516adf8632da52a59d11cffe99358699
4
+ data.tar.gz: e7bb8210daa809b122fb81b1126777cfec9ae437
5
5
  SHA512:
6
- metadata.gz: fdf7244fb9332a10169882b00bc2fb440505039e80be882a16b6f1ccad300223f10f3d7336aed605b86c555a67f7081fb26693fdb526473eaf3b6b408fafb118
7
- data.tar.gz: 6bb25c6ff24b83ba69fc444e29c682819226461e1e0498f16ed806f6004a6bb1da021495293080a6de719975eacd5d4795b75f6f5134df5e2f3fe42837aa0878
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
- # options - The Hash options used to create a Attribute (default: {}):
21
- # :type - The String data type of the custom attribute.
22
- # Can be String, Integer, Timestamp or Boolean.
23
- # :key - The String key of the custom attribute.
24
- # Accepts alphanumeric characters and underscores.
25
- # :value - The value of the custom attribute.
26
- # Should be of the data type as specified in *type*.
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, **options)
30
- Chartmogul::V1::Request.new "#{BASE_URI}/#{customer_id}/attributes/custom", options.merge(method: :post, userpwd: client.userpwd)
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
- # options - The Hash options used to refine the Customer attributes (default: {}).
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, **options)
43
- Chartmogul::V1::Request.new "#{BASE_URI}/#{customer_id}/attributes/custom", options.merge(method: :put, userpwd: client.userpwd)
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
- # userpwd - The String with credentials for Basic Authentication.
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, userpwd: nil, method: :get, **params)
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
- userpwd: userpwd,
23
+ body: body,
24
+ connecttimeout: 5,
25
+ headers: headers,
22
26
  method: method,
23
27
  params: params,
24
- connecttimeout: 5,
25
- timeout: 10
28
+ timeout: 10,
29
+ userpwd: userpwd,
26
30
  ).run
27
31
  end
28
32
 
@@ -1,5 +1,5 @@
1
1
  module Chartmogul
2
2
 
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
 
5
5
  end
@@ -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(:query) { { foo: 'bar' } }
17
+ let(:body) { [ {foo: 'bar'} ] }
18
+ let(:query) { {} }
18
19
 
19
20
  before do
20
- stub_request(:post, url).with(query: query).to_return(status: 200)
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', query) }
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(:query) { { foo: 'bar' } }
31
+ let(:body) { [ {foo: 'bar'} ] }
32
+ let(:query) { {} }
31
33
 
32
34
  before do
33
- stub_request(:put, url).with(query: query).to_return(status: 200)
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', query) }
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chartmogul_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Vokhmin