mcparty 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: d717f0b737c06dcb20518d9100c658c028f6140c
4
+ data.tar.gz: 1149c31803d5e21e6e75781b67e67f0ba0c44e76
5
+ SHA512:
6
+ metadata.gz: 403af8772f4a202f2b6d4525dbdb0f810828c91b11dd0717cf7a203d9de03ba5f5df0c7cd1185f211f8276da192ded163095fac11a9b1ee53c7cea700f7860a1
7
+ data.tar.gz: 6a61d56e63b7d3a03e99268b10c28a6b61f36f583899ca0ef83730ce828f29ee496af13bbfcf13b0f6f8b32546aad423fc5db80ec76edd339e1f4e90696b5f35
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mc-party.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Kale Davis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # MCParty
2
+
3
+ A very basic wrapper for the MailChimp API using HTTParty. Most likely you want to use [Gibbon](https://github.com/amro/gibbon).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'mcparty'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install mcparty
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ mc = MCParty.new("xxxxxxxxxxxxxxxxxxxxxxxxxx-us1")
25
+
26
+ # Get a list of your lists
27
+ mc.get("/lists")
28
+
29
+ # Add a new member
30
+ mc.post("/lists/xxxxxxx/members", body: {email_address: "test@example.com", status: "subscribed"})
31
+
32
+ # Note that you can use any verb supported by MailChimp: get post put patch delete
33
+
34
+ # Lastly, can handle the batches endpoint by passing an array of operations
35
+ mc.batches([{method: "GET", path: "/lists/aaaaaaa/members"}, {method: "GET", path: "/lists/bbbbbb/members"}])
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
40
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mcparty"
5
+ require "awesome_print"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "pry"
11
+ Pry.start
@@ -0,0 +1,73 @@
1
+ require "mcparty/version"
2
+ require "httparty"
3
+ require "json"
4
+
5
+ class MCParty
6
+ include HTTParty
7
+
8
+ def initialize(apikey, config={})
9
+ @auth = {username: 'apikey', password: apikey}
10
+ shard = apikey.split("-").last
11
+ self.class.base_uri "https://#{shard}.api.mailchimp.com/3.0"
12
+
13
+ @config = config
14
+ @config[:return_collections_as_arrays] = true
15
+ end
16
+
17
+ def md5(email)
18
+ Digest::MD5.hexdigest email
19
+ end
20
+
21
+ def batch(operations)
22
+ response = JSON.parse(self.class.post(
23
+ "/batches",
24
+ basic_auth: @auth,
25
+ body: { operations: operations}.to_json,
26
+ headers: { "Content-Type" => "application/json", "Accept" => "application/json"}
27
+ ).body)
28
+ end
29
+
30
+ %w(get post put patch delete).each do |method|
31
+ define_method method do |endpoint, opts={}|
32
+ call_endpoint(method.to_sym, endpoint, opts)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def call_endpoint(verb, endpoint, opts={})
39
+ config = @config.merge opts
40
+
41
+ #drop beginning / if present
42
+ endpoint = endpoint[1..-1] if endpoint[0] == "/"
43
+
44
+ endpoint = endpoint.split("/")
45
+
46
+ #turn emails into md5 hashes
47
+ endpoint = endpoint.map {|p| p.match("@") ? md5(p) : p}
48
+
49
+ # puts "/" + endpoint.join("/")
50
+
51
+ response = JSON.parse(self.class.send(verb,
52
+ "/" + endpoint.join("/"),
53
+ basic_auth: @auth,
54
+ headers: { "Content-Type" => "application/json", "Accept" => "application/json"},
55
+ body: opts[:body] ? opts[:body].to_json : nil,
56
+ query: opts[:query]
57
+ ).body)
58
+
59
+ if response.key?(endpoint.first) && response[endpoint.first].is_a?(Array)
60
+ #collection
61
+ unless config[:show_links]
62
+ response[endpoint.first].map do |r|
63
+ r.tap { |t| t.delete("_links") }
64
+ end
65
+ end
66
+
67
+ return config[:return_collections_as_arrays] ? response[endpoint.first] : response
68
+ else
69
+ response.delete("_links") unless config[:show_links]
70
+ return response
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ class MCParty
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mcparty/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mcparty"
8
+ spec.version = MCParty::VERSION
9
+ spec.authors = ["Kale Davis"]
10
+ spec.email = ["kale@simplerise.com"]
11
+
12
+ spec.summary = %q{A simple api wrapper for MailChimp using HTTParty}
13
+ spec.homepage = "https://gitlab.com/simplerise/mcparty"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "httparty"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.0"
26
+ spec.add_development_dependency "minitest-reporters"
27
+ spec.add_development_dependency "pry", "~> 0.10"
28
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mcparty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kale Davis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-reporters
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
97
+ description:
98
+ email:
99
+ - kale@simplerise.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .travis.yml
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/console
111
+ - lib/mcparty.rb
112
+ - lib/mcparty/version.rb
113
+ - mcparty.gemspec
114
+ homepage: https://gitlab.com/simplerise/mcparty
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.2.2
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: A simple api wrapper for MailChimp using HTTParty
138
+ test_files: []