customerio 5.3.0 → 6.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/README.md +146 -15
- data/lib/customerio/api.rb +71 -24
- data/lib/customerio/base_client.rb +26 -20
- data/lib/customerio/client.rb +153 -75
- data/lib/customerio/regions.rb +3 -4
- data/lib/customerio/requests/send_email_request.rb +22 -23
- data/lib/customerio/requests/send_in_app_request.rb +27 -0
- data/lib/customerio/requests/send_inbox_message_request.rb +27 -0
- data/lib/customerio/requests/send_push_request.rb +16 -15
- data/lib/customerio/requests/send_sms_request.rb +40 -0
- data/lib/customerio/requests/trigger_broadcast_request.rb +28 -0
- data/lib/customerio/version.rb +3 -1
- data/lib/customerio.rb +6 -1
- metadata +24 -89
- data/.github/workflows/main.yml +0 -21
- data/.gitignore +0 -20
- data/.gitpod.yml +0 -10
- data/CHANGELOG.markdown +0 -181
- data/Gemfile +0 -4
- data/Rakefile +0 -8
- data/customerio.gemspec +0 -26
- data/lib/customerio/param_encoder.rb +0 -68
- data/spec/api_client_spec.rb +0 -255
- data/spec/base_client_spec.rb +0 -67
- data/spec/client_spec.rb +0 -718
- data/spec/spec_helper.rb +0 -15
metadata
CHANGED
|
@@ -1,133 +1,73 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: customerio
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 6.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Allison
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: multi_json
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - "~>"
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '1.0'
|
|
20
|
-
type: :runtime
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - "~>"
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '1.0'
|
|
27
12
|
- !ruby/object:Gem::Dependency
|
|
28
13
|
name: addressable
|
|
29
14
|
requirement: !ruby/object:Gem::Requirement
|
|
30
15
|
requirements:
|
|
31
16
|
- - "~>"
|
|
32
17
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 2.
|
|
18
|
+
version: '2.9'
|
|
34
19
|
type: :runtime
|
|
35
20
|
prerelease: false
|
|
36
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
22
|
requirements:
|
|
38
23
|
- - "~>"
|
|
39
24
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: 2.
|
|
25
|
+
version: '2.9'
|
|
41
26
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
27
|
+
name: base64
|
|
43
28
|
requirement: !ruby/object:Gem::Requirement
|
|
44
29
|
requirements:
|
|
45
30
|
- - "~>"
|
|
46
31
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
48
|
-
type: :
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - "~>"
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '10.5'
|
|
55
|
-
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: rspec
|
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
|
58
|
-
requirements:
|
|
59
|
-
- - "~>"
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: '3.10'
|
|
62
|
-
type: :development
|
|
32
|
+
version: '0.3'
|
|
33
|
+
type: :runtime
|
|
63
34
|
prerelease: false
|
|
64
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
36
|
requirements:
|
|
66
37
|
- - "~>"
|
|
67
38
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '3
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
|
72
|
-
requirements:
|
|
73
|
-
- - '='
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
version: 3.6.0
|
|
76
|
-
type: :development
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - '='
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: 3.6.0
|
|
83
|
-
- !ruby/object:Gem::Dependency
|
|
84
|
-
name: json
|
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
|
86
|
-
requirements:
|
|
87
|
-
- - ">="
|
|
88
|
-
- !ruby/object:Gem::Version
|
|
89
|
-
version: '0'
|
|
90
|
-
type: :development
|
|
91
|
-
prerelease: false
|
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
-
requirements:
|
|
94
|
-
- - ">="
|
|
95
|
-
- !ruby/object:Gem::Version
|
|
96
|
-
version: '0'
|
|
97
|
-
description: A ruby client for the Customer.io event API.
|
|
39
|
+
version: '0.3'
|
|
40
|
+
description: A ruby client for the Customer.io Journeys Track API and Transactional
|
|
41
|
+
API.
|
|
98
42
|
email:
|
|
99
43
|
- john@customer.io
|
|
100
44
|
executables: []
|
|
101
45
|
extensions: []
|
|
102
46
|
extra_rdoc_files: []
|
|
103
47
|
files:
|
|
104
|
-
- ".github/workflows/main.yml"
|
|
105
|
-
- ".gitignore"
|
|
106
|
-
- ".gitpod.yml"
|
|
107
|
-
- CHANGELOG.markdown
|
|
108
|
-
- Gemfile
|
|
109
48
|
- LICENSE
|
|
110
49
|
- README.md
|
|
111
|
-
- Rakefile
|
|
112
|
-
- customerio.gemspec
|
|
113
50
|
- lib/customerio.rb
|
|
114
51
|
- lib/customerio/api.rb
|
|
115
52
|
- lib/customerio/base_client.rb
|
|
116
53
|
- lib/customerio/client.rb
|
|
117
|
-
- lib/customerio/param_encoder.rb
|
|
118
54
|
- lib/customerio/regions.rb
|
|
119
55
|
- lib/customerio/requests/send_email_request.rb
|
|
56
|
+
- lib/customerio/requests/send_in_app_request.rb
|
|
57
|
+
- lib/customerio/requests/send_inbox_message_request.rb
|
|
120
58
|
- lib/customerio/requests/send_push_request.rb
|
|
59
|
+
- lib/customerio/requests/send_sms_request.rb
|
|
60
|
+
- lib/customerio/requests/trigger_broadcast_request.rb
|
|
121
61
|
- lib/customerio/version.rb
|
|
122
|
-
- spec/api_client_spec.rb
|
|
123
|
-
- spec/base_client_spec.rb
|
|
124
|
-
- spec/client_spec.rb
|
|
125
|
-
- spec/spec_helper.rb
|
|
126
62
|
homepage: https://customer.io
|
|
127
63
|
licenses:
|
|
128
64
|
- MIT
|
|
129
|
-
metadata:
|
|
130
|
-
|
|
65
|
+
metadata:
|
|
66
|
+
bug_tracker_uri: https://github.com/customerio/customerio-ruby/issues
|
|
67
|
+
changelog_uri: https://github.com/customerio/customerio-ruby/releases
|
|
68
|
+
homepage_uri: https://customer.io
|
|
69
|
+
rubygems_mfa_required: 'true'
|
|
70
|
+
source_code_uri: https://github.com/customerio/customerio-ruby
|
|
131
71
|
rdoc_options: []
|
|
132
72
|
require_paths:
|
|
133
73
|
- lib
|
|
@@ -135,19 +75,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
135
75
|
requirements:
|
|
136
76
|
- - ">="
|
|
137
77
|
- !ruby/object:Gem::Version
|
|
138
|
-
version: '
|
|
78
|
+
version: '3.3'
|
|
139
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
80
|
requirements:
|
|
141
81
|
- - ">="
|
|
142
82
|
- !ruby/object:Gem::Version
|
|
143
83
|
version: '0'
|
|
144
84
|
requirements: []
|
|
145
|
-
rubygems_version: 3.
|
|
146
|
-
signing_key:
|
|
85
|
+
rubygems_version: 3.6.9
|
|
147
86
|
specification_version: 4
|
|
148
|
-
summary: A ruby client for the Customer.io
|
|
149
|
-
test_files:
|
|
150
|
-
- spec/api_client_spec.rb
|
|
151
|
-
- spec/base_client_spec.rb
|
|
152
|
-
- spec/client_spec.rb
|
|
153
|
-
- spec/spec_helper.rb
|
|
87
|
+
summary: A ruby client for the Customer.io Journeys Track API and Transactional API.
|
|
88
|
+
test_files: []
|
data/.github/workflows/main.yml
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
name: ci
|
|
2
|
-
|
|
3
|
-
on: [push,pull_request]
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
test:
|
|
7
|
-
strategy:
|
|
8
|
-
matrix:
|
|
9
|
-
ruby: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2']
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
env:
|
|
12
|
-
BUNDLE_PATH: ${{ github.workspace }}/vendor/bundle
|
|
13
|
-
steps:
|
|
14
|
-
- uses: actions/checkout@v2
|
|
15
|
-
- uses: ruby/setup-ruby@v1
|
|
16
|
-
with:
|
|
17
|
-
ruby-version: ${{ matrix.ruby }}
|
|
18
|
-
bundler-cache: true
|
|
19
|
-
|
|
20
|
-
- name: Unit Test w/ RSpec
|
|
21
|
-
run: bundle exec rspec
|
data/.gitignore
DELETED
data/.gitpod.yml
DELETED
data/CHANGELOG.markdown
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
## Customerio 5.3.0 - December 8, 2023
|
|
2
|
-
### Changed
|
|
3
|
-
- The `identify` method has been updated to allow the customer ID to be specified separately from the attributes, using the `customer_id` attribute. This allows a person to be updated by identifying them by e.g.: their email address. Thanks to trwalzer, jrbeck and jeremyw for the original changes that this is based on.
|
|
4
|
-
- It is no longer possible to set the `customer_id` attribute on a person. This is a side-effect of the changes to the `identify` method.
|
|
5
|
-
|
|
6
|
-
## Customerio 5.2.0 - December 8, 2023
|
|
7
|
-
### Changed
|
|
8
|
-
- The `identify` method will now automatically use the `cio_id` attribute as the customer ID when calling the track service. This allows a customer to be updated using `identify` to modify the `id` and `email` attributes.
|
|
9
|
-
|
|
10
|
-
## Customerio 5.1.0 - May 5, 2023
|
|
11
|
-
### Added
|
|
12
|
-
- Added `send_push` to `APIClient` and `SendPushRequest` to support sending transactional push notifications.
|
|
13
|
-
|
|
14
|
-
## Customerio 4.3.1 - January 5, 2023
|
|
15
|
-
### Added
|
|
16
|
-
- Added the `disable_css_preprocessing` and `language` optional fields to send request
|
|
17
|
-
|
|
18
|
-
## Customerio 4.3.0 - April 26, 2022
|
|
19
|
-
### Added
|
|
20
|
-
- Support for [anonymous invite events](https://customer.io/docs/anonymous-invite-emails/) by setting `anonymous_id` to `nil`.
|
|
21
|
-
|
|
22
|
-
## Customerio 4.1.0 - Sep 27, 2021
|
|
23
|
-
### Added
|
|
24
|
-
- Added support for [merge customers](https://customer.io/docs/api/#operation/merge) API
|
|
25
|
-
|
|
26
|
-
## Customerio 4.0.1 - July 13, 2021
|
|
27
|
-
### Changed
|
|
28
|
-
- Update addressable gem dependency to v2.8.0
|
|
29
|
-
|
|
30
|
-
## Customerio 4.0.0 - July 6, 2021
|
|
31
|
-
### Removed
|
|
32
|
-
- The `anonymous_track` method.
|
|
33
|
-
|
|
34
|
-
### Added
|
|
35
|
-
- The `track_anonymous` method replaces `anonymous_track`. This method requires an `anonymous_id` parameter and will no longer trigger campaigns. If you previously used anonymous events to trigger campaigns, you can still do so [directly through the API](https://customer.io/docs/api/#operation/trackAnonymous). We now refer to anonymous events that trigger campaigns as ["invite events"](https://customer.io/docs/anonymous-events/#anonymous-or-invite).
|
|
36
|
-
|
|
37
|
-
## Customerio 3.1.0 - March 25, 2021
|
|
38
|
-
### Added
|
|
39
|
-
- Support for EU region
|
|
40
|
-
|
|
41
|
-
### Removed
|
|
42
|
-
### Changed
|
|
43
|
-
- `Customerio::Client` and `CustomerIO::APIClient` have a new parameter `region` that can be set to either `Customerio::Regions::EU` or `Customerio::Regions::US` (defaults to `Customerio::Regions::US`)
|
|
44
|
-
|
|
45
|
-
## Customerio 3.0.0 - Dec 2, 2020
|
|
46
|
-
|
|
47
|
-
### Added
|
|
48
|
-
- Support for the Transactional API
|
|
49
|
-
|
|
50
|
-
### Removed
|
|
51
|
-
- `add_to_segment` and `remove_from_segment` methods
|
|
52
|
-
- Support for non-JSON data
|
|
53
|
-
|
|
54
|
-
### Changed
|
|
55
|
-
- IDs in the URLs are now escaped.
|
|
56
|
-
- Improved validations for data that's passed in.
|
|
57
|
-
- Earlier, if you passed in an event name without a customer ID to the `track` method, we would create an anonymous event. That is now removed. To create an anonymous event, use the `anonymous_track` method.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
## Customerio 3.0.0 - Dec 2, 2020
|
|
61
|
-
|
|
62
|
-
### Added
|
|
63
|
-
- Support for the Transactional API
|
|
64
|
-
|
|
65
|
-
### Removed
|
|
66
|
-
- `add_to_segment` and `remove_from_segment` methods
|
|
67
|
-
- Support for non-JSON data
|
|
68
|
-
|
|
69
|
-
### Changed
|
|
70
|
-
- IDs in the URLs are now escaped.
|
|
71
|
-
- Improved validations for data that's passed in.
|
|
72
|
-
- Earlier, if you passed in an event name without a customer ID to the `track` method, we would create an anonymous event. That is now removed. To create an anonymous event, use the `anonymous_track` method.
|
|
73
|
-
|
|
74
|
-
## Customerio 2.2.1 - Mar 23, 2020
|
|
75
|
-
|
|
76
|
-
- Add license to gemspec [#55](https://github.com/customerio/customerio-ruby/pull/55)
|
|
77
|
-
- Bubble up error message [#51](https://github.com/customerio/customerio-ruby/pull/51)
|
|
78
|
-
|
|
79
|
-
## Customerio 2.2.0 - Oct 18, 2018
|
|
80
|
-
|
|
81
|
-
Add support for manual segments [#52](https://github.com/customerio/customerio-ruby/pull/52)
|
|
82
|
-
|
|
83
|
-
## Customerio 2.1.0 - May 22, 2018
|
|
84
|
-
|
|
85
|
-
Added support for the suppress / unsuppress methods [#49](https://github.com/customerio/customerio-ruby/pull/49)
|
|
86
|
-
|
|
87
|
-
## Customerio 2.0.0 - Apr 10, 2018
|
|
88
|
-
|
|
89
|
-
With this release we have dropped the support for ruby 1.8.7.
|
|
90
|
-
|
|
91
|
-
- Support new add and remove device endpoints for push notifications [#47](https://github.com/customerio/customerio-ruby/pull/47)
|
|
92
|
-
|
|
93
|
-
## Customerio 1.0.0 - Mar 15, 2016
|
|
94
|
-
|
|
95
|
-
There is a slight breaking change in this release. If you are depending on the HTTP response object included in the InvalidResponse exception (introduced in 0.6.1), note that it is now a `Net::HTTPBadRequest`.
|
|
96
|
-
|
|
97
|
-
- Remove HTTParty dependency, use Net::HTTP instead. [#42](https://github.com/customerio/customerio-ruby/pull/42)
|
|
98
|
-
|
|
99
|
-
- Update test suite to use webmock, to increase confidence that we're not changing our HTTP requests [#41](https://github.com/customerio/customerio-ruby/pull/41)
|
|
100
|
-
|
|
101
|
-
## Customerio 0.7.0 - Mar 2, 2016
|
|
102
|
-
|
|
103
|
-
- Add new method for tracking anonymous events: `anonymous_track`. See README for more details. Many thanks to @sdawson for this contribution! [#36](https://github.com/customerio/customerio-ruby/pull/36)
|
|
104
|
-
|
|
105
|
-
- Use JSON encoding by default. [#37](https://github.com/customerio/customerio-ruby/pull/37)
|
|
106
|
-
|
|
107
|
-
If you want to stick with form-encoding for your integration, you must add `:json => false` to your Customerio::Client initializer. Like this:
|
|
108
|
-
|
|
109
|
-
```ruby
|
|
110
|
-
customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY", :json => false)
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
## Customerio 0.6.1 - Oct 8, 2015
|
|
114
|
-
|
|
115
|
-
- Include HTTP response as an attribute on the InvalidResponse exception to help with debugging failed API requests. For example:
|
|
116
|
-
|
|
117
|
-
```ruby
|
|
118
|
-
begin
|
|
119
|
-
$customerio.track(1, 'event', { :test => 'testing' })
|
|
120
|
-
rescue => e
|
|
121
|
-
puts e.message
|
|
122
|
-
puts e.response.status
|
|
123
|
-
puts e.response.body
|
|
124
|
-
end
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
## Customerio 0.6.0 - Oct 6, 2015
|
|
128
|
-
|
|
129
|
-
Deprecation warning: we are going to switch to JSON encoding by default for the next release. The current default is form-encoding. This will probably not affect you, unless you rely on how form-encoding arrays work.
|
|
130
|
-
|
|
131
|
-
If you want to stick with form-encoding for your integration, you must add `:json => false` to your Customerio::Client initializer. Like this:
|
|
132
|
-
|
|
133
|
-
```ruby
|
|
134
|
-
customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY", :json => false)
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
Other fixes and improvements, with many thanks to the community contributors:
|
|
138
|
-
|
|
139
|
-
- Added HTTP timeout of 10 seconds (@stayhero)
|
|
140
|
-
- Added JSON support for events (@kemper)
|
|
141
|
-
- Convert attribute keys to symbols (@joshnabbott)
|
|
142
|
-
|
|
143
|
-
## Customerio 0.5.0 - Mar 28, 2014
|
|
144
|
-
|
|
145
|
-
- Added flag to send body encoded as JSON, rather than the default form encoding.
|
|
146
|
-
|
|
147
|
-
## Customerio 0.5.0 - Apr 8, 2013
|
|
148
|
-
|
|
149
|
-
- Removed deprecated methods around using a customer object. All calls simply take a hash of attributes now.
|
|
150
|
-
- Added ability to set a timestamp on a tracked event. Useful for backfilling past events.
|
|
151
|
-
|
|
152
|
-
## Customerio 0.4.1 - Feb 18, 2013
|
|
153
|
-
|
|
154
|
-
- Bug fixes related to the 4.0 change.
|
|
155
|
-
|
|
156
|
-
## Customerio 0.4.0 - Feb 18, 2013
|
|
157
|
-
|
|
158
|
-
- Added support for deleting customers.
|
|
159
|
-
|
|
160
|
-
## Customerio 0.3.0 - Dec 28, 2012
|
|
161
|
-
|
|
162
|
-
- Now raise an error if an API call doesn't respond with a 200 response code
|
|
163
|
-
- Removed dependency on ActiveSupport
|
|
164
|
-
|
|
165
|
-
## Customerio 0.2.0 - Nov 21, 2012
|
|
166
|
-
|
|
167
|
-
- Allow raw hashes to be passed into `identify` and `track` methods rather than a customer object.
|
|
168
|
-
- Passing a customer object has been depreciated.
|
|
169
|
-
- Customizing ids with `Customerio::Client.id` block is deprecated.
|
|
170
|
-
|
|
171
|
-
## Customerio 0.1.0 - Nov 15, 2012
|
|
172
|
-
|
|
173
|
-
- Allow tracking of anonymous events.
|
|
174
|
-
|
|
175
|
-
## Customerio 0.0.3 - Nov 5, 2012
|
|
176
|
-
|
|
177
|
-
- Bump httparty dependency to the latest version.
|
|
178
|
-
|
|
179
|
-
## Customerio 0.0.2 - May 22, 2012
|
|
180
|
-
|
|
181
|
-
- First release.
|
data/Gemfile
DELETED
data/Rakefile
DELETED
data/customerio.gemspec
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
|
2
|
-
require File.expand_path('../lib/customerio/version', __FILE__)
|
|
3
|
-
|
|
4
|
-
Gem::Specification.new do |gem|
|
|
5
|
-
gem.authors = ["John Allison"]
|
|
6
|
-
gem.email = ["john@customer.io"]
|
|
7
|
-
gem.description = "A ruby client for the Customer.io event API."
|
|
8
|
-
gem.summary = "A ruby client for the Customer.io event API."
|
|
9
|
-
gem.homepage = "https://customer.io"
|
|
10
|
-
gem.license = "MIT"
|
|
11
|
-
|
|
12
|
-
gem.files = `git ls-files`.split($\)
|
|
13
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
14
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
15
|
-
gem.name = "customerio"
|
|
16
|
-
gem.require_paths = ["lib"]
|
|
17
|
-
gem.version = Customerio::VERSION
|
|
18
|
-
|
|
19
|
-
gem.add_dependency('multi_json', "~> 1.0")
|
|
20
|
-
gem.add_dependency('addressable', '~> 2.8.0')
|
|
21
|
-
|
|
22
|
-
gem.add_development_dependency('rake', '~> 10.5')
|
|
23
|
-
gem.add_development_dependency('rspec', '~> 3.10')
|
|
24
|
-
gem.add_development_dependency('webmock', '3.6.0')
|
|
25
|
-
gem.add_development_dependency('json')
|
|
26
|
-
end
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# Based on HTTParty's HashConversions:
|
|
2
|
-
#
|
|
3
|
-
# https://github.com/jnunemaker/httparty/blob/master/lib/httparty/hash_conversions.rb
|
|
4
|
-
#
|
|
5
|
-
# License: MIT https://github.com/jnunemaker/httparty/blob/master/MIT-LICENSE
|
|
6
|
-
|
|
7
|
-
require 'erb'
|
|
8
|
-
require 'uri'
|
|
9
|
-
|
|
10
|
-
module Customerio
|
|
11
|
-
class ParamEncoder
|
|
12
|
-
# @return <String> This hash as a query string
|
|
13
|
-
#
|
|
14
|
-
# @example
|
|
15
|
-
# { name: "Bob",
|
|
16
|
-
# address: {
|
|
17
|
-
# street: '111 Ruby Ave.',
|
|
18
|
-
# city: 'Ruby Central',
|
|
19
|
-
# phones: ['111-111-1111', '222-222-2222']
|
|
20
|
-
# }
|
|
21
|
-
# }.to_params
|
|
22
|
-
# #=> "name=Bob&address[city]=Ruby Central&address[phones][]=111-111-1111&address[phones][]=222-222-2222&address[street]=111 Ruby Ave."
|
|
23
|
-
def self.to_params(hash)
|
|
24
|
-
hash.to_hash.map { |k, v| normalize_param(k, v) }.join.chop
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# @param key<Object> The key for the param.
|
|
28
|
-
# @param value<Object> The value for the param.
|
|
29
|
-
#
|
|
30
|
-
# @return <String> This key value pair as a param
|
|
31
|
-
#
|
|
32
|
-
# @example normalize_param(:name, "Bob Jones") #=> "name=Bob%20Jones&"
|
|
33
|
-
def self.normalize_param(key, value)
|
|
34
|
-
param = ''
|
|
35
|
-
stack = []
|
|
36
|
-
|
|
37
|
-
if value.respond_to?(:to_ary)
|
|
38
|
-
param << value.to_ary.map { |element| normalize_param("#{key}[]", element) }.join
|
|
39
|
-
elsif value.respond_to?(:to_hash)
|
|
40
|
-
stack << [key, value.to_hash]
|
|
41
|
-
else
|
|
42
|
-
param << "#{key}=#{escape_value(value)}&"
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
stack.each do |parent, hash|
|
|
46
|
-
hash.each do |k, v|
|
|
47
|
-
if v.respond_to?(:to_hash)
|
|
48
|
-
stack << ["#{parent}[#{k}]", v.to_hash]
|
|
49
|
-
else
|
|
50
|
-
param << normalize_param("#{parent}[#{k}]", v)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
param
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# Prefer ERB::Util.url_encode, fall back to deprecation URI.encode for
|
|
59
|
-
# old Ruby support
|
|
60
|
-
def self.escape_value(value)
|
|
61
|
-
if ERB::Util.respond_to? :url_encode
|
|
62
|
-
ERB::Util.url_encode(value.to_s)
|
|
63
|
-
else
|
|
64
|
-
URI.encode(value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|