customerio 0.5.0 → 0.5.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0bbd80c03cec96e156a839df078eea4f2d58bfde
4
+ data.tar.gz: fe118df2f5e167994e0f51914812610839eb9bde
5
+ SHA512:
6
+ metadata.gz: e57f979df8e8fb749178c77e6e21e210ddbacf7eee8eaea0f68f67cf0ec6037d80bd4a3db969325eca55fdae565bbd46d5169dce143950c095b3b777dd1b9949
7
+ data.tar.gz: a7e39880c576e2f3945f228d09649ee1c281d508d08fbe44f7de9beb982ba46b0dd2dd16b0a2b273e9d027cd485458ac39674423d3e2f6c0c6638a1de5e4e369
@@ -1,3 +1,7 @@
1
+ ## Customerio 0.5.0 - Mar 28, 2014 ##
2
+
3
+ * Added flag to send body encoded as JSON, rather than the default form encoding.
4
+
1
5
  ## Customerio 0.5.0 - Apr 8, 2013 ##
2
6
 
3
7
  * Removed deprecated methods around using a customer object. All calls simply take a hash of attributes now.
@@ -1,4 +1,5 @@
1
1
  require 'httparty'
2
+ require 'json'
2
3
 
3
4
  module Customerio
4
5
  class Client
@@ -8,8 +9,9 @@ module Customerio
8
9
  class MissingIdAttributeError < RuntimeError; end
9
10
  class InvalidResponse < RuntimeError; end
10
11
 
11
- def initialize(site_id, secret_key)
12
+ def initialize(site_id, secret_key, options = {})
12
13
  @auth = { :username => site_id, :password => secret_key }
14
+ @json = options[:json]
13
15
  end
14
16
 
15
17
  def identify(attributes)
@@ -43,7 +45,11 @@ module Customerio
43
45
 
44
46
  url = customer_path(attributes[:id])
45
47
 
46
- verify_response(self.class.put(url, options.merge(:body => attributes)))
48
+ if @json
49
+ verify_response(self.class.put(url, options.merge(:body => attributes.to_json, :headers => {'Content-Type' => 'application/json'})))
50
+ else
51
+ verify_response(self.class.put(url, options.merge(:body => attributes)))
52
+ end
47
53
  end
48
54
 
49
55
  def create_customer_event(customer_id, event_name, attributes = {})
@@ -1,3 +1,3 @@
1
1
  module Customerio
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -47,7 +47,11 @@ which can be found in your [customer.io settings](https://app.customer.io/settin
47
47
 
48
48
  If you're using Rails, create an initializer `config/initializers/customerio.rb`:
49
49
 
50
- $customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY")
50
+ customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY")
51
+
52
+ If you'd like to send complex data to associate to a user as json, pass a json option:
53
+
54
+ customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY", :json => true)
51
55
 
52
56
  ### Identify logged in customers
53
57
 
@@ -75,7 +79,7 @@ key information changes. This keeps [Customer.io](http://customer.io) up to date
75
79
  # information that would be useful in your triggers. You
76
80
  # must at least pass in an id, email, and created_at timestamp.
77
81
 
78
- $customerio.identify(
82
+ customerio.identify(
79
83
  :id => 5,
80
84
  :email => "bob@example.com,
81
85
  :created_at => customer.created_at.to_i,
@@ -95,7 +99,7 @@ recreated.
95
99
  # should be the same id you'd pass into the
96
100
  # `identify` command above.
97
101
 
98
- $customerio.delete(5)
102
+ customerio.delete(5)
99
103
 
100
104
  ### Tracking a custom event
101
105
 
@@ -111,12 +115,12 @@ encourage your customers to perform an action.
111
115
  # event. These attributes can be used in your triggers to control who should
112
116
  # receive the triggered email. You can set any number of data values.
113
117
 
114
- $customerio.track(5, "purchase", :type => "socks", :price => "13.99")
118
+ customerio.track(5, "purchase", :type => "socks", :price => "13.99")
115
119
 
116
120
  **Note:** If you'd like to track events which occurred in the past, you can include a `timestamp` attribute
117
121
  (in seconds since the epoch), and we'll use that as the date the event occurred.
118
122
 
119
- $customerio.track(5, "purchase", :type => "socks", :price => "13.99", :timestamp => 1365436200)
123
+ customerio.track(5, "purchase", :type => "socks", :price => "13.99", :timestamp => 1365436200)
120
124
 
121
125
  ## Contributing
122
126
 
@@ -22,6 +22,16 @@ describe Customerio::Client do
22
22
  client.identify(:id => 5)
23
23
  end
24
24
 
25
+ it "sends a PUT request to customer.io's customer API using json headers" do
26
+ client = Customerio::Client.new("SITE_ID", "API_KEY", :json => true)
27
+ Customerio::Client.should_receive(:put).with(
28
+ "/api/v1/customers/5",
29
+ {:basic_auth=>{:username=>"SITE_ID", :password=>"API_KEY"},
30
+ :body=>"{\"id\":5,\"name\":\"Bob\"}",
31
+ :headers=>{"Content-Type"=>"application/json"}}).and_return(response)
32
+ client.identify(:id => 5, :name => "Bob")
33
+ end
34
+
25
35
  it "raises an error if PUT doesn't return a 2xx response code" do
26
36
  Customerio::Client.should_receive(:put).and_return(mock("Response", :code => 500))
27
37
  lambda { client.identify(:id => 5) }.should raise_error(Customerio::Client::InvalidResponse)
metadata CHANGED
@@ -1,84 +1,75 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: customerio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
5
- prerelease:
4
+ version: 0.5.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - John Allison
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-08 00:00:00.000000000 Z
11
+ date: 2014-03-28 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: httparty
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - <
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.0'
22
- - - ! '>='
20
+ - - '>='
23
21
  - !ruby/object:Gem::Version
24
22
  version: '0.5'
25
23
  type: :runtime
26
24
  prerelease: false
27
25
  version_requirements: !ruby/object:Gem::Requirement
28
- none: false
29
26
  requirements:
30
27
  - - <
31
28
  - !ruby/object:Gem::Version
32
29
  version: '1.0'
33
- - - ! '>='
30
+ - - '>='
34
31
  - !ruby/object:Gem::Version
35
32
  version: '0.5'
36
33
  - !ruby/object:Gem::Dependency
37
34
  name: rake
38
35
  requirement: !ruby/object:Gem::Requirement
39
- none: false
40
36
  requirements:
41
- - - ! '>='
37
+ - - '>='
42
38
  - !ruby/object:Gem::Version
43
39
  version: '0'
44
40
  type: :development
45
41
  prerelease: false
46
42
  version_requirements: !ruby/object:Gem::Requirement
47
- none: false
48
43
  requirements:
49
- - - ! '>='
44
+ - - '>='
50
45
  - !ruby/object:Gem::Version
51
46
  version: '0'
52
47
  - !ruby/object:Gem::Dependency
53
48
  name: rspec
54
49
  requirement: !ruby/object:Gem::Requirement
55
- none: false
56
50
  requirements:
57
- - - ! '>='
51
+ - - '>='
58
52
  - !ruby/object:Gem::Version
59
53
  version: '0'
60
54
  type: :development
61
55
  prerelease: false
62
56
  version_requirements: !ruby/object:Gem::Requirement
63
- none: false
64
57
  requirements:
65
- - - ! '>='
58
+ - - '>='
66
59
  - !ruby/object:Gem::Version
67
60
  version: '0'
68
61
  - !ruby/object:Gem::Dependency
69
62
  name: fakeweb
70
63
  requirement: !ruby/object:Gem::Requirement
71
- none: false
72
64
  requirements:
73
- - - ! '>='
65
+ - - '>='
74
66
  - !ruby/object:Gem::Version
75
67
  version: '0'
76
68
  type: :development
77
69
  prerelease: false
78
70
  version_requirements: !ruby/object:Gem::Requirement
79
- none: false
80
71
  requirements:
81
- - - ! '>='
72
+ - - '>='
82
73
  - !ruby/object:Gem::Version
83
74
  version: '0'
84
75
  description: A ruby client for the Customer.io event API.
@@ -104,27 +95,26 @@ files:
104
95
  - spec/spec_helper.rb
105
96
  homepage: http://customer.io
106
97
  licenses: []
98
+ metadata: {}
107
99
  post_install_message:
108
100
  rdoc_options: []
109
101
  require_paths:
110
102
  - lib
111
103
  required_ruby_version: !ruby/object:Gem::Requirement
112
- none: false
113
104
  requirements:
114
- - - ! '>='
105
+ - - '>='
115
106
  - !ruby/object:Gem::Version
116
107
  version: '0'
117
108
  required_rubygems_version: !ruby/object:Gem::Requirement
118
- none: false
119
109
  requirements:
120
- - - ! '>='
110
+ - - '>='
121
111
  - !ruby/object:Gem::Version
122
112
  version: '0'
123
113
  requirements: []
124
114
  rubyforge_project:
125
- rubygems_version: 1.8.24
115
+ rubygems_version: 2.0.3
126
116
  signing_key:
127
- specification_version: 3
117
+ specification_version: 4
128
118
  summary: A ruby client for the Customer.io event API.
129
119
  test_files:
130
120
  - spec/client_spec.rb