maropost_api 0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3dec12bbcd69b4de22fecc58ef26326909abf416
4
+ data.tar.gz: 1bdaec6856c63cae7227cd0c0acc2fc18261f2fd
5
+ SHA512:
6
+ metadata.gz: 925d3d0c7365978e72244f8d0e172c401fa54698314acce3d0a7d02bb2e176ab1e9bba04e9c88faf7f035def1590b5dac98855886df4f5b90896f281385ce286
7
+ data.tar.gz: 11300e4d906d9994979425e78613e867078d317272a5f5c201acc0a31dd8401d77a8bb375b3a7afd78a0f69dc148860e93777694c5fdc9bea987d6105aea0cf6
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .*.swp
11
+ .*.swo
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in maropost_api.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Hossein Toussi, Haidar Muhammad
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,50 @@
1
+ # MaropostApi
2
+
3
+ A simple ruby wrapper for Maropost (http://maropost.com/) API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'maropost_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install maropost_api
20
+
21
+ ## Usage
22
+
23
+ Initialize a Client object with `client = MaropostApi::Client.new(auth_token: '<TOKEN>', account_number: '<ID>')`
24
+ And here are the methods available:
25
+
26
+ ``` ruby
27
+ # To find a contact by email:
28
+ client.contacts.add_to_list(email: 'test@example.com')
29
+
30
+ # To add a contact to a list
31
+ client.contacts.add_to_list(list_ids: '<id>', params: {email: 'test@example.com'})
32
+
33
+ # To update a contact
34
+ client.contacts.update(list_ids: '<id>', params: {email: 'test@example.com', first_name: 'test-updated'})
35
+ ```
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hosseintoussi/maropost_api.
46
+
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ task :console do
9
+ exec "irb -r maropost_api -I ./lib"
10
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'maropost_api'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ require "hashie"
2
+ require "maropost_api/version"
3
+ require "maropost_api/request"
4
+ require "maropost_api/errors"
5
+ require "maropost_api/response"
6
+ require "maropost_api/client"
7
+ require "maropost_api/contacts"
8
+
9
+ module MaropostApi
10
+ end
@@ -0,0 +1,11 @@
1
+ module MaropostApi
2
+ class Client
3
+ def initialize(auth_token:, account_number:)
4
+ @request = Request.new(auth_token: auth_token, account_number: account_number)
5
+ end
6
+
7
+ def contacts
8
+ @contacts ||= Contacts.new(request: @request)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module MaropostApi
2
+ class Contacts
3
+ def initialize(request:)
4
+ @request = request
5
+ end
6
+
7
+ def find_by_email(email:)
8
+ response = @request.get(endpoint: "contacts/email.json?contact[email]=#{email}")
9
+ Response.new(response: response).call
10
+ end
11
+
12
+ def add_to_list(list_ids: "", params:)
13
+ response = @request.post(endpoint: "contacts.json?list_ids=#{list_ids}", params: params)
14
+ Response.new(response: response).call
15
+ end
16
+ alias_method :update, :add_to_list
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ module MaropostApi
2
+ class Errors < StandardError; end
3
+ class InternalServerError < Errors; end
4
+ class BadRequest < Errors; end
5
+ class Unauthorized < Errors; end
6
+ class NotFound < Errors; end
7
+ class UnprocessableEntity < Errors; end
8
+ end
@@ -0,0 +1,41 @@
1
+ require 'httparty'
2
+
3
+ module MaropostApi
4
+ class Request
5
+ include HTTParty
6
+
7
+ def initialize(auth_token:, account_number:)
8
+ @auth_token = auth_token
9
+ @account_number = account_number
10
+ set_default_config
11
+ end
12
+
13
+ def post(endpoint:, params: {})
14
+ self.class.post(uri(endpoint), payload(params))
15
+ end
16
+
17
+ def get(endpoint:, params: {})
18
+ self.class.get(uri(endpoint), payload(params))
19
+ end
20
+
21
+ private
22
+
23
+ def set_default_config
24
+ @base_uri = "http://api.maropost.com/accounts/#{@account_number}"
25
+ @default_params = { auth_token: @auth_token }
26
+ end
27
+
28
+ def uri(endpoint)
29
+ "#{@base_uri}/#{endpoint}"
30
+ end
31
+
32
+ def payload(params)
33
+ { body: merge_auth_token(params).to_json,
34
+ headers: { 'Content-Type' => 'application/json' } }
35
+ end
36
+
37
+ def merge_auth_token(params)
38
+ @default_params.merge(params)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,24 @@
1
+ module MaropostApi
2
+ class Response
3
+ def initialize(response: {})
4
+ @response = response
5
+ end
6
+
7
+ def call
8
+ case @response.code
9
+ when 400
10
+ raise BadRequest.new
11
+ when 401...402
12
+ raise Unauthorized.new
13
+ when 404
14
+ raise NotFound.new
15
+ when 422
16
+ raise UnprocessableEntity.new
17
+ when 500
18
+ raise InternalServerError.new
19
+ else
20
+ Hashie::Mash.new(@response)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module MaropostApi
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "maropost_api/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "maropost_api"
8
+ spec.version = MaropostApi::VERSION
9
+ spec.authors = ["Hossein Toussi", "Haidar Muhammad"]
10
+ spec.email = ["saeed.toussi@yahoo.com", "haidar.muhammad@gmail.com"]
11
+
12
+ spec.summary = "Wrapper gem for Maropost API"
13
+ spec.homepage = "https://github.com/hosseintoussi/maropost_api"
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_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "vcr"
25
+ spec.add_development_dependency "webmock"
26
+ spec.add_development_dependency "pry"
27
+
28
+ spec.add_runtime_dependency "httparty"
29
+ spec.add_runtime_dependency "hashie"
30
+ end
@@ -0,0 +1,50 @@
1
+ # MaropostApi
2
+
3
+ A simple ruby wrapper for Maropost (http://maropost.com/) API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'maropost_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install maropost_api
20
+
21
+ ## Usage
22
+
23
+ Initialize a Client object with `client = MaropostApi::Client.new(auth_token: '<TOKEN>', account_number: '<ID>')`
24
+ And here are the methods available:
25
+
26
+ ``` ruby
27
+ # To find a contact by email:
28
+ client.contacts.add_to_list(email: 'test@example.com')
29
+
30
+ # To add a contact to a list
31
+ client.contacts.add_to_list(list_ids: '<id>', params: {email: 'test@example.com'})
32
+
33
+ # To update a contact
34
+ client.contacts.update(list_ids: '<id>', params: {email: 'test@example.com', first_name: 'test-updated'})
35
+ ```
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hosseintoussi/maropost_api.
46
+
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maropost_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hossein Toussi
8
+ - Haidar Muhammad
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-07-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.11'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.11'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: vcr
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: webmock
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: pry
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: httparty
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: hashie
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description:
127
+ email:
128
+ - saeed.toussi@yahoo.com
129
+ - haidar.muhammad@gmail.com
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".gitignore"
135
+ - ".rspec"
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - bin/console
141
+ - bin/setup
142
+ - lib/maropost_api.rb
143
+ - lib/maropost_api/client.rb
144
+ - lib/maropost_api/contacts.rb
145
+ - lib/maropost_api/errors.rb
146
+ - lib/maropost_api/request.rb
147
+ - lib/maropost_api/response.rb
148
+ - lib/maropost_api/version.rb
149
+ - maropost_api.gemspec
150
+ - readme.md
151
+ homepage: https://github.com/hosseintoussi/maropost_api
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.4.8
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Wrapper gem for Maropost API
175
+ test_files: []