maropost_api 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3dec12bbcd69b4de22fecc58ef26326909abf416
4
- data.tar.gz: 1bdaec6856c63cae7227cd0c0acc2fc18261f2fd
3
+ metadata.gz: 719f8e25c9902556c46859bbf07004cfa6a78dd2
4
+ data.tar.gz: 8b518df8320edf648deed400f8fe72a9570f8153
5
5
  SHA512:
6
- metadata.gz: 925d3d0c7365978e72244f8d0e172c401fa54698314acce3d0a7d02bb2e176ab1e9bba04e9c88faf7f035def1590b5dac98855886df4f5b90896f281385ce286
7
- data.tar.gz: 11300e4d906d9994979425e78613e867078d317272a5f5c201acc0a31dd8401d77a8bb375b3a7afd78a0f69dc148860e93777694c5fdc9bea987d6105aea0cf6
6
+ metadata.gz: fd9d04ce6243580b1de26463ad156bbe6eab222750b956251fab2a7da3bd0e619bfdcf6680b7d731762664ca364960c99dabe20354337193151bd072fcb982a4
7
+ data.tar.gz: 801292ed6c319e945e77b1bc30bbd1afcfc9b2454f60cbec168da6ed38a384588dff7e89eeb06147d37a5f7402b0d21209503d5f18ec53926fab6f5e9e1e85fa
data/lib/maropost_api.rb CHANGED
@@ -3,8 +3,11 @@ require "maropost_api/version"
3
3
  require "maropost_api/request"
4
4
  require "maropost_api/errors"
5
5
  require "maropost_api/response"
6
+ require "maropost_api/parser/entity_parser"
7
+ require "maropost_api/parser/message_body_parser"
6
8
  require "maropost_api/client"
7
9
  require "maropost_api/contacts"
10
+ require "maropost_api/workflows"
8
11
 
9
12
  module MaropostApi
10
13
  end
@@ -7,5 +7,9 @@ module MaropostApi
7
7
  def contacts
8
8
  @contacts ||= Contacts.new(request: @request)
9
9
  end
10
+
11
+ def workflows
12
+ @workflows ||= Workflows.new(request: @request)
13
+ end
10
14
  end
11
15
  end
@@ -2,17 +2,32 @@ module MaropostApi
2
2
  class Contacts
3
3
  def initialize(request:)
4
4
  @request = request
5
+ @parser = Parser::EntityParser.new
5
6
  end
6
7
 
7
8
  def find_by_email(email:)
8
- response = @request.get(endpoint: "contacts/email.json?contact[email]=#{email}")
9
- Response.new(response: response).call
9
+ response = @request.get(endpoint: "/contacts/email.json?contact[email]=#{email}")
10
+ Response.new(response: response, parser: @parser).call
10
11
  end
11
12
 
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
13
+ def add_to_list(list_ids:, params:)
14
+ response = @request.post(endpoint: "/contacts.json?list_ids=#{list_ids}", params: params)
15
+ Response.new(response: response, parser: @parser).call
16
+ end
17
+
18
+ def create(params:)
19
+ response = @request.post(endpoint: "/contacts.json", params: params)
20
+ Response.new(response: response, parser: @parser).call
21
+ end
22
+
23
+ def update(contact_id:, params:)
24
+ response = @request.put(endpoint: "/contacts/#{contact_id}.json", params: params)
25
+ Response.new(response: response, parser: @parser).call
26
+ end
27
+
28
+ def unsubscribe_all_lists(email:)
29
+ response = @request.put(endpoint: "/contacts/unsubscribe_all.json?contact[email]=#{email}")
30
+ Response.new(response: response, parser: @parser).call
15
31
  end
16
- alias_method :update, :add_to_list
17
32
  end
18
33
  end
@@ -0,0 +1,9 @@
1
+ module MaropostApi
2
+ module Parser
3
+ class EntityParser
4
+ def call(response)
5
+ Hashie::Mash.new(response)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module MaropostApi
2
+ module Parser
3
+ class MessageBodyParser
4
+ def call(response)
5
+ Hashie::Mash.new(message: response.body)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -18,6 +18,10 @@ module MaropostApi
18
18
  self.class.get(uri(endpoint), payload(params))
19
19
  end
20
20
 
21
+ def put(endpoint:, params: {})
22
+ self.class.put(uri(endpoint), payload(params))
23
+ end
24
+
21
25
  private
22
26
 
23
27
  def set_default_config
@@ -26,7 +30,7 @@ module MaropostApi
26
30
  end
27
31
 
28
32
  def uri(endpoint)
29
- "#{@base_uri}/#{endpoint}"
33
+ Addressable::URI.encode("#{@base_uri}#{endpoint}")
30
34
  end
31
35
 
32
36
  def payload(params)
@@ -1,7 +1,8 @@
1
1
  module MaropostApi
2
2
  class Response
3
- def initialize(response: {})
3
+ def initialize(response: {}, parser:)
4
4
  @response = response
5
+ @parser = parser
5
6
  end
6
7
 
7
8
  def call
@@ -17,7 +18,7 @@ module MaropostApi
17
18
  when 500
18
19
  raise InternalServerError.new
19
20
  else
20
- Hashie::Mash.new(@response)
21
+ @parser.call(@response)
21
22
  end
22
23
  end
23
24
  end
@@ -1,3 +1,3 @@
1
1
  module MaropostApi
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -0,0 +1,24 @@
1
+ module MaropostApi
2
+ class Workflows
3
+ def initialize(request:)
4
+ @request = request
5
+ @body_parser = Parser::MessageBodyParser.new
6
+ @entity_parser = Parser::EntityParser.new
7
+ end
8
+
9
+ def stop(workflow_id:, contact_id:)
10
+ response = @request.put(endpoint: "/workflows/#{workflow_id}/stop/#{contact_id}.json")
11
+ Response.new(response: response, parser: @body_parser).call
12
+ end
13
+
14
+ def start(workflow_id:, contact_id:)
15
+ response = @request.put(endpoint: "/workflows/#{workflow_id}/start/#{contact_id}.json")
16
+ Response.new(response: response, parser: @body_parser).call
17
+ end
18
+
19
+ def reset(workflow_id:, contact_id:)
20
+ response = @request.put(endpoint: "/workflows/#{workflow_id}/reset/#{contact_id}.json")
21
+ Response.new(response: response, parser: @entity_parser).call
22
+ end
23
+ end
24
+ end
data/maropost_api.gemspec CHANGED
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
 
28
28
  spec.add_runtime_dependency "httparty"
29
29
  spec.add_runtime_dependency "hashie"
30
+ spec.add_runtime_dependency "addressable"
30
31
  end
data/readme.md CHANGED
@@ -20,18 +20,37 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- Initialize a Client object with `client = MaropostApi::Client.new(auth_token: '<TOKEN>', account_number: '<ID>')`
24
23
  And here are the methods available:
25
24
 
26
25
  ``` ruby
26
+ # Initialize a Client object with:
27
+ client = MaropostApi::Client.new(auth_token: '<TOKEN>', account_number: '<ID>')
28
+
29
+ # And use the client to perform available functionalities.
30
+
27
31
  # To find a contact by email:
28
- client.contacts.add_to_list(email: 'test@example.com')
32
+ client.contacts.find_by_email(email: 'test@example.com')
29
33
 
30
34
  # To add a contact to a list
31
35
  client.contacts.add_to_list(list_ids: '<id>', params: {email: 'test@example.com'})
32
36
 
37
+ # To create a contact without any lists
38
+ client.contacts.create(params: {email: 'test@example.com'})
39
+
33
40
  # To update a contact
34
- client.contacts.update(list_ids: '<id>', params: {email: 'test@example.com', first_name: 'test-updated'})
41
+ client.contacts.update(contact_id: '<id>', params: {email: 'test@example.com', first_name: 'test-updated'})
42
+
43
+ # To unsubscribe a contact from all lists
44
+ client.contacts.unsubscribe_all_lists(email: 'test@example.com')
45
+
46
+ # To start a workflow for a contact
47
+ client.workflows.start(workflow_id: '<workflow_id>', contact_id: '<contact_id>')
48
+
49
+ # To stop a workflow for a contact
50
+ client.workflows.stop(workflow_id: '<workflow_id>', contact_id: '<contact_id>')
51
+
52
+ # To reset a workflow for a contact
53
+ client.workflows.reset(workflow_id: '<workflow_id>', contact_id: '<contact_id>')
35
54
  ```
36
55
 
37
56
  ## Development
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maropost_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hossein Toussi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-07-13 00:00:00.000000000 Z
12
+ date: 2016-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -123,6 +123,20 @@ dependencies:
123
123
  - - ">="
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: addressable
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
126
140
  description:
127
141
  email:
128
142
  - saeed.toussi@yahoo.com
@@ -135,7 +149,6 @@ files:
135
149
  - ".rspec"
136
150
  - Gemfile
137
151
  - LICENSE.txt
138
- - README.md
139
152
  - Rakefile
140
153
  - bin/console
141
154
  - bin/setup
@@ -143,9 +156,12 @@ files:
143
156
  - lib/maropost_api/client.rb
144
157
  - lib/maropost_api/contacts.rb
145
158
  - lib/maropost_api/errors.rb
159
+ - lib/maropost_api/parser/entity_parser.rb
160
+ - lib/maropost_api/parser/message_body_parser.rb
146
161
  - lib/maropost_api/request.rb
147
162
  - lib/maropost_api/response.rb
148
163
  - lib/maropost_api/version.rb
164
+ - lib/maropost_api/workflows.rb
149
165
  - maropost_api.gemspec
150
166
  - readme.md
151
167
  homepage: https://github.com/hosseintoussi/maropost_api
data/README.md DELETED
@@ -1,50 +0,0 @@
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).