mandao 0.0.3 → 0.0.4
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/lib/mandao.rb +59 -2
- data/lib/mandao/configuration.rb +0 -1
- data/lib/mandao/resources/address_list.rb +6 -5
- data/lib/mandao/resources/base.rb +7 -6
- data/lib/mandao/resources/document.rb +5 -3
- data/lib/mandao/version.rb +1 -1
- data/lib/mandao/xml_format.rb +8 -0
- data/spec/mandao/address_list_spec.rb +1 -1
- data/spec/mandao/document_spec.rb +1 -1
- data/spec/mandao/stub_requests.rb +1 -1
- data/spec/spec_helper.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e85c84b6f00855322d61b55216bef33bfaf1ecec
|
4
|
+
data.tar.gz: ba375ed671f5e2a74a1039d2b6c2f59b9ea10062
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c24b0a89a64dac20debb9cbac56c5e220975bc0665dd2f9e1d7e68c193bfcf9d2a25c9c6d3b3d15e61771d9196ac24539d1d242bb97debb510d621e68e7d2cc2
|
7
|
+
data.tar.gz: c5b6a04b1c0a29088947e0030bda475c46cda010734b1f193bd171f7b7be8bfc72c92011c92e30432061df1ab0f4a630a3c74afcf966ce0f16eb29283dd6844d
|
data/lib/mandao.rb
CHANGED
@@ -1,4 +1,61 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'rest_client'
|
4
|
+
require 'active_resource'
|
5
|
+
|
1
6
|
require 'mandao/version'
|
2
|
-
Dir.glob(File.expand_path('../resources/*', __FILE__)).each { |file| require(file) }
|
3
7
|
require 'mandao/xml_format'
|
4
|
-
require 'mandao/
|
8
|
+
require 'mandao/resources/base'
|
9
|
+
|
10
|
+
module Mandao
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :configuration
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.configure
|
17
|
+
self.configuration ||= Configuration.new
|
18
|
+
yield(configuration)
|
19
|
+
Mandao::Base.activate(api_endpoint: Mandao.config.api_endpoint, default_format: Mandao.config.format)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.config
|
23
|
+
self.configuration
|
24
|
+
end
|
25
|
+
|
26
|
+
class Configuration
|
27
|
+
attr_accessor :endpoint
|
28
|
+
attr_accessor :username
|
29
|
+
attr_accessor :password
|
30
|
+
attr_accessor :protocol
|
31
|
+
attr_accessor :format
|
32
|
+
|
33
|
+
VALID_OPTIONS_KEYS = [:endpoint, :username, :password]
|
34
|
+
REQUIRED_OPTIONS = [:username, :password]
|
35
|
+
DEFAULT_PROTOCOL = "https".freeze
|
36
|
+
DEFAULT_ENDPOINT = 'stage.rest.click2mail.com/v1'.freeze # TODO [ add production endpoint by default ]
|
37
|
+
DEFAULT_FORMAT = ActiveResource::Formats::XmlFormat
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
@endpoint = DEFAULT_ENDPOINT
|
41
|
+
@protocol = DEFAULT_PROTOCOL
|
42
|
+
@format = DEFAULT_FORMAT
|
43
|
+
end
|
44
|
+
|
45
|
+
def api_endpoint
|
46
|
+
"#{@protocol}://#{@username}:#{@password}@#{@endpoint}/"
|
47
|
+
end
|
48
|
+
|
49
|
+
def valid?
|
50
|
+
REQUIRED_OPTIONS.each do |opt|
|
51
|
+
raise StandardError, 'You must provide username and password.' if send(opt)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
require 'mandao/resources/address'
|
60
|
+
require 'mandao/resources/address_list'
|
61
|
+
require 'mandao/resources/document'
|
data/lib/mandao/configuration.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
-
require 'rest_client'
|
2
|
-
require 'active_resource'
|
3
|
-
require File.expand_path('../address', __FILE__)
|
4
|
-
|
5
1
|
module Mandao
|
6
2
|
|
7
3
|
class AddressListCollection < ActiveResource::Collection
|
8
4
|
def initialize(parsed = {})
|
9
5
|
attrs = []
|
6
|
+
parsed['addressList']
|
10
7
|
attrs << parsed['addressList'] if parsed['addressList'].is_a? Hash
|
11
|
-
@elements = attrs
|
8
|
+
@elements = if attrs.present?
|
9
|
+
attrs
|
10
|
+
else
|
11
|
+
parsed['addressList']
|
12
|
+
end
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
@@ -1,15 +1,16 @@
|
|
1
|
-
require 'active_resource'
|
2
|
-
require File.expand_path('../../configuration', __FILE__)
|
3
|
-
|
4
1
|
module Mandao
|
5
2
|
class Base < ActiveResource::Base
|
6
3
|
self.include_format_in_path = false
|
7
4
|
|
8
5
|
class << self
|
9
6
|
|
10
|
-
def activate
|
11
|
-
|
12
|
-
|
7
|
+
def activate(options={})
|
8
|
+
begin
|
9
|
+
self.site = options[:api_endpoint]
|
10
|
+
self.format = options[:default_format]
|
11
|
+
rescue
|
12
|
+
raise 'Missing api_endpoint, default_format configuration'
|
13
|
+
end
|
13
14
|
end
|
14
15
|
|
15
16
|
def parse_response(xml)
|
@@ -1,12 +1,14 @@
|
|
1
|
-
require 'rest_client'
|
2
|
-
|
3
1
|
module Mandao
|
4
2
|
|
5
3
|
class DocumentCollection < ActiveResource::Collection
|
6
4
|
def initialize(parsed = {})
|
7
5
|
attrs = []
|
8
6
|
attrs << parsed['document'] if parsed['document'].is_a? Hash
|
9
|
-
@elements = attrs
|
7
|
+
@elements = if attrs.present?
|
8
|
+
attrs
|
9
|
+
else
|
10
|
+
parsed['document']
|
11
|
+
end
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
data/lib/mandao/version.rb
CHANGED
data/lib/mandao/xml_format.rb
CHANGED
@@ -17,7 +17,7 @@ def stub_document_post
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def stub_address_lists
|
20
|
-
xml = "<addressLists
|
20
|
+
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<addressLists>\n <addressList>\n <id>55738</id>\n <ready>false</ready>\n <total>0</total>\n </addressList>\n <addressList>\n <id>55739</id>\n <ready>false</ready>\n <total>0</total>\n </addressList>\n</addressLists>\n"
|
21
21
|
stub_request(:get, "https://username:password@#{ Mandao::Configuration::DEFAULT_ENDPOINT }/addressLists").
|
22
22
|
to_return(:status => 200, :body => xml, :headers => {})
|
23
23
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,10 +4,10 @@ require 'active_resource'
|
|
4
4
|
require 'rest_client'
|
5
5
|
|
6
6
|
require File.expand_path('../../lib/mandao', __FILE__)
|
7
|
-
require File.expand_path('../../lib/mandao/resources/base', __FILE__)
|
8
|
-
require File.expand_path('../../lib/mandao/xml_format', __FILE__)
|
7
|
+
# require File.expand_path('../../lib/mandao/resources/base', __FILE__)
|
8
|
+
# require File.expand_path('../../lib/mandao/xml_format', __FILE__)
|
9
9
|
require File.expand_path('..//mandao/stub_requests', __FILE__)
|
10
|
-
Dir.glob(File.expand_path('../../lib/mandao/resources/*', __FILE__)).each { |file| require(file) }
|
10
|
+
# Dir.glob(File.expand_path('../../lib/mandao/resources/*', __FILE__)).each { |file| require(file) }
|
11
11
|
|
12
12
|
RSpec.configure do |config|
|
13
13
|
config.include WebMock::API
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mandao
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marlon Mantilla
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeresource
|