mandao 0.0.1 → 0.0.2pre
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/.gitignore +2 -0
- data/.rspec +2 -0
- data/lib/mandao/configuration.rb +49 -0
- data/lib/mandao/resources/address.rb +35 -0
- data/lib/mandao/resources/address_list.rb +49 -0
- data/lib/mandao/resources/base.rb +19 -0
- data/lib/mandao/resources/document.rb +24 -0
- data/lib/mandao/version.rb +1 -1
- data/lib/mandao/xml_format.rb +16 -0
- data/lib/mandao.rb +2 -5
- data/mandao.gemspec +7 -2
- data/spec/mandao/address_list_spec.rb +37 -0
- data/spec/mandao/document_spec.rb +26 -0
- data/spec/mandao/files/document.pdf +1641 -0
- data/spec/mandao/stub_requests.rb +29 -0
- data/spec/mandao_spec.rb +18 -0
- data/spec/spec_helper.rb +14 -0
- metadata +69 -17
- data/push/.gitignore +0 -14
- data/push/Gemfile +0 -4
- data/push/LICENSE.txt +0 -22
- data/push/README.md +0 -31
- data/push/Rakefile +0 -2
- data/push/lib/push/version.rb +0 -3
- data/push/lib/push.rb +0 -5
- data/push/push.gemspec +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4be4b5ae37269795d42e7b34ba1f9e1ddab0f0a1
|
4
|
+
data.tar.gz: 5cd84033120c48876de7f6f0ce53aa6be32ef31c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe717b0cb9ea9249bef8d4dabd5dc4993cc00a1d14094e570af80ea49868fd6600f4f6cbca389fd6e7b579a3c31b371fabdbf86ab5ed067e0c23f6c98aeb2471
|
7
|
+
data.tar.gz: 2f154fe98a9e903fba86e928e10793b0f032fc22d5f53e078e3dd67bd5bff5d630ef8f28baff23141fbc9c0191f3a9e27737f0921426ee201e39ca69f0dc3d62
|
data/.gitignore
CHANGED
@@ -22,6 +22,7 @@ mkmf.log
|
|
22
22
|
/test/tmp/
|
23
23
|
/test/version_tmp/
|
24
24
|
/tmp/
|
25
|
+
/push/
|
25
26
|
|
26
27
|
## Specific to RubyMotion:
|
27
28
|
.dat*
|
@@ -38,6 +39,7 @@ build/
|
|
38
39
|
/.bundle/
|
39
40
|
/lib/bundler/man/
|
40
41
|
|
42
|
+
|
41
43
|
# for a library or gem, you might want to ignore these files since the code is
|
42
44
|
# intended to run in multiple environments; otherwise, check them in:
|
43
45
|
# Gemfile.lock
|
data/.rspec
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
|
2
|
+
module Mandao
|
3
|
+
|
4
|
+
class << self
|
5
|
+
attr_accessor :configuration
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.configure
|
9
|
+
self.configuration ||= Configuration.new
|
10
|
+
yield(configuration)
|
11
|
+
Mandao::Base.activate
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.config
|
15
|
+
self.configuration
|
16
|
+
end
|
17
|
+
|
18
|
+
class Configuration
|
19
|
+
attr_accessor :endpoint
|
20
|
+
attr_accessor :username
|
21
|
+
attr_accessor :password
|
22
|
+
attr_accessor :protocol
|
23
|
+
attr_accessor :format
|
24
|
+
|
25
|
+
VALID_OPTIONS_KEYS = [:endpoint, :username, :password]
|
26
|
+
REQUIRED_OPTIONS = [:username, :password]
|
27
|
+
DEFAULT_PROTOCOL = "https".freeze
|
28
|
+
DEFAULT_ENDPOINT = 'stage.rest.click2mail.com/v1'.freeze # TODO [ add production endpoint by default ]
|
29
|
+
DEFAULT_FORMAT = ActiveResource::Formats::XmlFormat
|
30
|
+
|
31
|
+
def initialize
|
32
|
+
@endpoint = DEFAULT_ENDPOINT
|
33
|
+
@protocol = DEFAULT_PROTOCOL
|
34
|
+
@format = DEFAULT_FORMAT
|
35
|
+
end
|
36
|
+
|
37
|
+
def api_endpoint
|
38
|
+
"#{@protocol}://#{@username}:#{@password}@#{@endpoint}/"
|
39
|
+
end
|
40
|
+
|
41
|
+
def valid?
|
42
|
+
REQUIRED_OPTIONS.each do |opt|
|
43
|
+
raise StandardError, 'You must provide username and password.' if send(opt)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Mandao
|
2
|
+
class Address
|
3
|
+
attr_accessor :first_name, :last_name, :organization, :address1,
|
4
|
+
:address2, :address3, :city, :state, :zip, :country_non_us
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
@first_name = options[:first_name]
|
8
|
+
@last_name = options[:last_name]
|
9
|
+
@organization = options[:organization]
|
10
|
+
@address1 = options[:address1]
|
11
|
+
@address2 = options[:address2]
|
12
|
+
@address3 = options[:address3]
|
13
|
+
@city = options[:city]
|
14
|
+
@state = options[:state]
|
15
|
+
@zip = options[:zip]
|
16
|
+
@country_non_us = options[:country_non_us]
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_xml
|
20
|
+
"<address>
|
21
|
+
<First_name>#{ @first_name }</First_name>
|
22
|
+
<Last_Name>#{ @last_name }</Last_Name>
|
23
|
+
<Organization>#{ @organization }</Organization>
|
24
|
+
<Address1>#{ @address1 }</Address1>
|
25
|
+
<Address2>#{ @address2 }</Address2>
|
26
|
+
<Address3>#{ @address3 }</Address3>
|
27
|
+
<City>#{@city}</City>
|
28
|
+
<State>#{@state}</State>
|
29
|
+
<Zip>#{@zip}</Zip>
|
30
|
+
<Country_non-US>#{@country_non_us}</Country_non-US>
|
31
|
+
</address>"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Mandao
|
2
|
+
|
3
|
+
class AddressListCollection < ActiveResource::Collection
|
4
|
+
def initialize(parsed = {})
|
5
|
+
attrs = []
|
6
|
+
attrs << parsed['addressList'] if parsed['addressList'].is_a? Hash
|
7
|
+
@elements = attrs || parsed['addressList']
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class AddressList < Base
|
12
|
+
self.collection_name = "addressLists"
|
13
|
+
self.collection_parser = Mandao::AddressListCollection
|
14
|
+
|
15
|
+
class << self
|
16
|
+
|
17
|
+
def create(list_name, addresses=[])
|
18
|
+
if list_name && addresses
|
19
|
+
xml = generate_xml(addresses)
|
20
|
+
begin
|
21
|
+
response = RestClient.post("#{self.site}#{ self.collection_name }", xml, content_type: :xml )
|
22
|
+
attrs = parse_response(response)
|
23
|
+
Mandao::AddressList.new(attrs)
|
24
|
+
rescue
|
25
|
+
end
|
26
|
+
else
|
27
|
+
raise StandardError, 'Address List must contain a name and at least one address.'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def generate_xml(addresses)
|
32
|
+
addresses_xml = ""
|
33
|
+
addresses.each do |address_attrs|
|
34
|
+
addresses_xml += Mandao::Address.new(address_attrs).to_xml
|
35
|
+
end
|
36
|
+
"<addressList>
|
37
|
+
<addressListName>Best Customers test</addressListName>
|
38
|
+
<addressMappingId>2</addressMappingId>
|
39
|
+
<addresses>
|
40
|
+
#{ addresses_xml }
|
41
|
+
</addresses>
|
42
|
+
</addressList>"
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mandao
|
2
|
+
class Base < ActiveResource::Base
|
3
|
+
self.include_format_in_path = false
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def activate
|
8
|
+
self.site = Mandao.config.api_endpoint
|
9
|
+
self.format = Mandao.config.format
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse_response(xml)
|
13
|
+
ActiveResource::Formats::XmlFormat.decode(xml)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Mandao
|
2
|
+
|
3
|
+
class DocumentCollection < ActiveResource::Collection
|
4
|
+
def initialize(parsed = {})
|
5
|
+
attrs = []
|
6
|
+
attrs << parsed['document'] if parsed['document'].is_a? Hash
|
7
|
+
@elements = attrs || parsed['document']
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Document < Base
|
12
|
+
self.collection_parser = Mandao::DocumentCollection
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def create(file, content_type='application/pdf')
|
16
|
+
response = RestClient.post("#{self.site}documents", file, content_type: content_type, accept: 'application/xml')
|
17
|
+
attrs = parse_response(response)
|
18
|
+
Mandao::Document.new(attrs)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/mandao/version.rb
CHANGED
data/lib/mandao.rb
CHANGED
data/mandao.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Marlon Mantilla"]
|
10
10
|
spec.email = ["me@marlonmantilla.com"]
|
11
11
|
spec.summary = %q{Mandao is a cool gem for accessing the Click2Mail REST API. https://developers.click2mail.com/rest-api/molpro/getting-started/main}
|
12
|
-
spec.description = %q{Mandao
|
12
|
+
spec.description = %q{Mandao allows you to access Click2Mail REST services in a simple way.}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
@@ -18,7 +18,12 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_runtime_dependency "activeresource", "~> 4.0"
|
22
|
+
spec.add_runtime_dependency "rest-client", "~> 1.7"
|
23
|
+
|
21
24
|
spec.add_development_dependency "bundler", "~> 1.7"
|
22
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
-
spec.add_development_dependency "rspec", "~> 3.1
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
27
|
+
spec.add_development_dependency "webmock", "~> 1.19"
|
28
|
+
|
24
29
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Mandao::AddressList do
|
4
|
+
|
5
|
+
before do
|
6
|
+
Mandao.configure do |config|
|
7
|
+
config.endpoint = Mandao::Configuration::DEFAULT_ENDPOINT
|
8
|
+
config.username = "username"
|
9
|
+
config.password = "password"
|
10
|
+
end
|
11
|
+
stub_address_lists
|
12
|
+
stub_address_lists_post
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should return all address lists' do
|
16
|
+
address_lists = Mandao::AddressList.all
|
17
|
+
expect(address_lists).to be_present
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should create an address list' do
|
21
|
+
address_lists = [{
|
22
|
+
first_name: 'John',
|
23
|
+
last_name: 'Doe',
|
24
|
+
organization: 'Umbrella',
|
25
|
+
address1: '742 Evergreen Terrace',
|
26
|
+
address2: '743 Evergreen Terrace',
|
27
|
+
address3: '',
|
28
|
+
city: 'Springfield',
|
29
|
+
state: 'MA',
|
30
|
+
zip: '12345',
|
31
|
+
country_non_us: ''
|
32
|
+
}]
|
33
|
+
address_list = Mandao::AddressList.create("My Address List", address_lists)
|
34
|
+
expect(address_list).to be_present
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Mandao::Document do
|
4
|
+
|
5
|
+
before do
|
6
|
+
Mandao.configure do |config|
|
7
|
+
config.endpoint = Mandao::Configuration::DEFAULT_ENDPOINT
|
8
|
+
config.username = "username"
|
9
|
+
config.password = "password"
|
10
|
+
end
|
11
|
+
stub_documents
|
12
|
+
stub_document_post
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should return all documents' do
|
16
|
+
documents = Mandao::Document.all
|
17
|
+
expect(documents).to be_present
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should create a document with a pdf' do
|
21
|
+
pdf = File.open(File.expand_path('../files/document.pdf', __FILE__), 'rb')
|
22
|
+
document = Mandao::Document.create(pdf)
|
23
|
+
expect(document).to be_present
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|