gibbon 3.0.2 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of gibbon might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/README.markdown +27 -0
- data/gibbon.gemspec +2 -2
- data/lib/gibbon.rb +1 -0
- data/lib/gibbon/export.rb +93 -0
- data/lib/gibbon/request.rb +8 -0
- data/lib/gibbon/version.rb +1 -1
- data/spec/gibbon/export_spec.rb +32 -0
- data/spec/gibbon/gibbon_spec.rb +9 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cadad0262542fdc59cf9296a13273855c6060de0
|
4
|
+
data.tar.gz: 58cd1444c3e4cf456fa06386adbc3a4135ce9b46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f147ecf3ab960b613cd4f8623cc1ae06d40d1835f7d72af08bf6624dc1417a178671d69010eb3c5ed9fb8697e3d6b0426ba531ae31cdf4a812d527909cbb3678
|
7
|
+
data.tar.gz: 057fae67da3e668dcee8f38d3b2a2aa099523458dab1a04725e57a730674633603a596857776026201c929ba956f55939bef40b61f7ad4597c87e5aba24e255c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
## [Unreleased][unreleased]
|
2
2
|
|
3
|
+
## [3.1.0] - 2017-07-27
|
4
|
+
- Add back support for Export API until MailChimp stops supporting it
|
5
|
+
- Implement `responds_to_missing`
|
6
|
+
|
3
7
|
## [3.0.2] - 2017-05-08
|
4
8
|
- Fix subtle bug in `symbolize_keys` when parsing error
|
5
9
|
|
@@ -69,7 +73,9 @@
|
|
69
73
|
## [1.1.4] - 2012-11-04
|
70
74
|
- Fix JSON::ParserError on export calls that return blank results
|
71
75
|
|
72
|
-
[unreleased]: https://github.com/amro/gibbon/compare/v3.0
|
76
|
+
[unreleased]: https://github.com/amro/gibbon/compare/v3.1.0...HEAD
|
77
|
+
[3.1.0]: https://github.com/amro/gibbon/compare/v3.0.2...v3.1.0
|
78
|
+
[3.0.2]: https://github.com/amro/gibbon/compare/v3.0.1...v3.0.2
|
73
79
|
[3.0.1]: https://github.com/amro/gibbon/compare/v3.0.0...v3.0.1
|
74
80
|
[3.0.0]: https://github.com/amro/gibbon/compare/v2.2.5...v3.0.0
|
75
81
|
[2.2.5]: https://github.com/amro/gibbon/compare/v2.2.4...v2.2.5
|
data/README.markdown
CHANGED
@@ -458,6 +458,33 @@ Gibbon 2.x+:
|
|
458
458
|
```ruby
|
459
459
|
gibbon.lists(list_id).members.create(body: {email_address: "foo@bar.com", status: "subscribed", merge_fields: {FNAME: "Bob", LNAME: "Smith"}})
|
460
460
|
```
|
461
|
+
## Export API 1.0
|
462
|
+
|
463
|
+
Gibbon 3.0.0+ supports MailChimp's [Export API 1.0](https://apidocs.mailchimp.com/export/1.0/). You can choose to handle the API response all at
|
464
|
+
once or line by line by passing a block. To access the Export API with Gibbon, you must first create an instance of `Gibbon::Export`:
|
465
|
+
|
466
|
+
```ruby
|
467
|
+
export = Gibbon::Export.new(api_key: "your_api_key")
|
468
|
+
```
|
469
|
+
|
470
|
+
Next, call the method corresponding to the API endpoint you'd like to query:
|
471
|
+
|
472
|
+
```ruby
|
473
|
+
export.list(id: list_id)
|
474
|
+
```
|
475
|
+
|
476
|
+
This fetches and returns all of the results at once. Pass a block if you'd like to handle the response as individual lines:
|
477
|
+
|
478
|
+
```ruby
|
479
|
+
export = Gibbon::Export.new(api_key: "your_api_key", timeout: 1200)
|
480
|
+
export.list(id: list_id) do |row|
|
481
|
+
puts row
|
482
|
+
end
|
483
|
+
```
|
484
|
+
|
485
|
+
This is useful when handling large sets of data. Setting the `timeout` here is optional, but a high value is recommended given the nature of the Export API. The default timeout is 600 seconds.
|
486
|
+
|
487
|
+
Gibbon supports all current Export API endpoints: `/list`, `/ecommOrders`, and `/campaignSubscriberActivity`. They're mapped onto Ruby methods with similar names: `list()`, `ecomm_orders()`, and `campaign_subscriber_activity()` respectively. Please see [MailChimp's API documentation](https://developer.mailchimp.com/documentation/mailchimp/guides/how-to-use-the-export-api/) for supported parameters.
|
461
488
|
|
462
489
|
## Thanks
|
463
490
|
|
data/gibbon.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = ["amromousa@gmail.com"]
|
10
10
|
s.homepage = "http://github.com/amro/gibbon"
|
11
11
|
|
12
|
-
s.summary = %q{A wrapper for MailChimp API 3.0}
|
13
|
-
s.description = %q{A wrapper for MailChimp API 3.0}
|
12
|
+
s.summary = %q{A wrapper for MailChimp API 3.0 and Export API}
|
13
|
+
s.description = %q{A wrapper for MailChimp API 3.0 and Export API}
|
14
14
|
s.license = "MIT"
|
15
15
|
|
16
16
|
s.rubyforge_project = "gibbon"
|
data/lib/gibbon.rb
CHANGED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
|
3
|
+
module Gibbon
|
4
|
+
class Export
|
5
|
+
include Helpers
|
6
|
+
|
7
|
+
attr_accessor :api_key, :timeout
|
8
|
+
|
9
|
+
def initialize(api_key: nil, timeout: nil)
|
10
|
+
@api_key = api_key || self.class.api_key
|
11
|
+
@timeout = timeout || self.class.timeout || 600
|
12
|
+
end
|
13
|
+
|
14
|
+
def list(params = {}, &block)
|
15
|
+
call("list", params, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def ecomm_orders(params = {}, &block)
|
19
|
+
call("ecommOrders", params, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def campaign_subscriber_activity(params = {}, &block)
|
23
|
+
call("campaignSubscriberActivity", params, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def export_api_url
|
29
|
+
"https://#{get_data_center_from_api_key(@api_key)}api.mailchimp.com/export/1.0/"
|
30
|
+
end
|
31
|
+
|
32
|
+
def call(method, params = {}, &block)
|
33
|
+
rows = []
|
34
|
+
|
35
|
+
api_url = export_api_url + method + "/"
|
36
|
+
params = params.merge({ apikey: @api_key })
|
37
|
+
block = Proc.new { |row| rows << row } unless block_given?
|
38
|
+
|
39
|
+
ensure_api_key(params)
|
40
|
+
|
41
|
+
url = URI.parse(api_url)
|
42
|
+
req = Net::HTTP::Post.new(url.path, initheader = {'Content-Type' => 'application/json'})
|
43
|
+
req.body = MultiJson.dump(params)
|
44
|
+
Net::HTTP.start(url.host, url.port, read_timeout: @timeout, use_ssl: true) do |http|
|
45
|
+
# http://stackoverflow.com/questions/29598196/ruby-net-http-read-body-nethttpokread-body-called-twice-ioerror
|
46
|
+
http.request req do |response|
|
47
|
+
i = -1
|
48
|
+
last = ''
|
49
|
+
response.read_body do |chunk|
|
50
|
+
next if chunk.nil? or chunk.strip.empty?
|
51
|
+
infix = "\n" if last[-1, 1]==']'
|
52
|
+
lines, last = try_parse_line("#{last}#{infix}#{chunk}")
|
53
|
+
lines.each { |line| block.call(line, i += 1) }
|
54
|
+
end
|
55
|
+
block.call(parse_line(last), i += 1) unless last.nil? or last.empty?
|
56
|
+
end
|
57
|
+
end
|
58
|
+
rows unless block_given?
|
59
|
+
end
|
60
|
+
|
61
|
+
def try_parse_line(res)
|
62
|
+
lines = res.split("\n")
|
63
|
+
last = lines.pop || ''
|
64
|
+
lines.map! { |line| parse_line(line) }
|
65
|
+
[lines.compact, last]
|
66
|
+
rescue MultiJson::ParseError
|
67
|
+
[[], last]
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def parse_line(line)
|
72
|
+
parsed_response = MultiJson.load(line)
|
73
|
+
rescue MultiJson::ParseError
|
74
|
+
return []
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def ensure_api_key(params)
|
80
|
+
unless params[:apikey] && (get_data_center_from_api_key(params[:apikey]) != "")
|
81
|
+
raise Gibbon::GibbonError, "You must set an api_key prior to making a call"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class << self
|
86
|
+
attr_accessor :api_key, :timeout
|
87
|
+
|
88
|
+
def method_missing(sym, *args, &block)
|
89
|
+
new(api_key: self.api_key, timeout: self.timeout).send(sym, *args, &block)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/lib/gibbon/request.rb
CHANGED
@@ -27,6 +27,10 @@ module Gibbon
|
|
27
27
|
self
|
28
28
|
end
|
29
29
|
|
30
|
+
def respond_to_missing?(method_name, include_private = false)
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
30
34
|
def send(*args)
|
31
35
|
if args.length == 0
|
32
36
|
method_missing(:send, args)
|
@@ -81,6 +85,10 @@ module Gibbon
|
|
81
85
|
def method_missing(sym, *args, &block)
|
82
86
|
new(api_key: self.api_key, api_endpoint: self.api_endpoint, timeout: self.timeout, open_timeout: self.open_timeout, faraday_adapter: self.faraday_adapter, symbolize_keys: self.symbolize_keys, debug: self.debug, proxy: self.proxy, logger: self.logger).send(sym, *args, &block)
|
83
87
|
end
|
88
|
+
|
89
|
+
def respond_to_missing?(method_name, include_private = false)
|
90
|
+
true
|
91
|
+
end
|
84
92
|
end
|
85
93
|
end
|
86
94
|
end
|
data/lib/gibbon/version.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'webmock/rspec'
|
3
|
+
|
4
|
+
describe Gibbon::Export do
|
5
|
+
before do
|
6
|
+
Gibbon::Export.send(:public, *Gibbon::Export.protected_instance_methods)
|
7
|
+
@export = Gibbon::Export.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "doesn't allow empty api key" do
|
11
|
+
expect {@export.list(id: "123456")}.to raise_error(Gibbon::GibbonError)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "doesn't allow api key without data center" do
|
15
|
+
@api_key = "123"
|
16
|
+
@export.api_key = @api_key
|
17
|
+
expect {@export.list(id: "123456")}.to raise_error(Gibbon::GibbonError)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "sets correct endpoint from api key" do
|
21
|
+
@api_key = "TESTKEY-us1"
|
22
|
+
@export.api_key = @api_key
|
23
|
+
expect(@export.export_api_url).to eq("https://us1.api.mailchimp.com/export/1.0/")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sets correct timeout" do
|
27
|
+
@api_key = "TESTKEY-us1"
|
28
|
+
@export.api_key = @api_key
|
29
|
+
@export.timeout = 9
|
30
|
+
expect(@export.timeout).to eq(9)
|
31
|
+
end
|
32
|
+
end
|
data/spec/gibbon/gibbon_spec.rb
CHANGED
@@ -222,4 +222,13 @@ describe Gibbon do
|
|
222
222
|
expect(Gibbon::Request.new.logger).to eq(logger)
|
223
223
|
end
|
224
224
|
end
|
225
|
+
|
226
|
+
describe "missing methods" do
|
227
|
+
it "respond to .method call on class" do
|
228
|
+
expect(Gibbon::Request.method(:lists)).to be_a(Method)
|
229
|
+
end
|
230
|
+
it "respond to .method call on instance" do
|
231
|
+
expect(Gibbon::Request.new.method(:lists)).to be_a(Method)
|
232
|
+
end
|
233
|
+
end
|
225
234
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gibbon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amro Mousa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 1.21.0
|
83
|
-
description: A wrapper for MailChimp API 3.0
|
83
|
+
description: A wrapper for MailChimp API 3.0 and Export API
|
84
84
|
email:
|
85
85
|
- amromousa@gmail.com
|
86
86
|
executables: []
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- gibbon.gemspec
|
99
99
|
- lib/gibbon.rb
|
100
100
|
- lib/gibbon/api_request.rb
|
101
|
+
- lib/gibbon/export.rb
|
101
102
|
- lib/gibbon/gibbon_error.rb
|
102
103
|
- lib/gibbon/gibbon_helpers.rb
|
103
104
|
- lib/gibbon/mailchimp_error.rb
|
@@ -105,6 +106,7 @@ files:
|
|
105
106
|
- lib/gibbon/response.rb
|
106
107
|
- lib/gibbon/version.rb
|
107
108
|
- spec/gibbon/api_request_spec.rb
|
109
|
+
- spec/gibbon/export_spec.rb
|
108
110
|
- spec/gibbon/gibbon_spec.rb
|
109
111
|
- spec/gibbon/upsert_spec.rb
|
110
112
|
- spec/spec_helper.rb
|
@@ -131,9 +133,10 @@ rubyforge_project: gibbon
|
|
131
133
|
rubygems_version: 2.4.6
|
132
134
|
signing_key:
|
133
135
|
specification_version: 4
|
134
|
-
summary: A wrapper for MailChimp API 3.0
|
136
|
+
summary: A wrapper for MailChimp API 3.0 and Export API
|
135
137
|
test_files:
|
136
138
|
- spec/gibbon/api_request_spec.rb
|
139
|
+
- spec/gibbon/export_spec.rb
|
137
140
|
- spec/gibbon/gibbon_spec.rb
|
138
141
|
- spec/gibbon/upsert_spec.rb
|
139
142
|
- spec/spec_helper.rb
|