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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 283514286e8a45320e9455b7ea5261e53633fffd
4
- data.tar.gz: bfed794aab83411b262b6823f3c9afa9bd4640f2
3
+ metadata.gz: e85c84b6f00855322d61b55216bef33bfaf1ecec
4
+ data.tar.gz: ba375ed671f5e2a74a1039d2b6c2f59b9ea10062
5
5
  SHA512:
6
- metadata.gz: dca5d0b8c7b2de887cd267fabf96673c575eb6ff04ade9dc0a57437ac3dc8d45e2158fdfb5f152b55ed328d4790c31ef5c3392f0939218139700f20ca53fca15
7
- data.tar.gz: 35f9fb1c9202f6806746c71639b9a3cadd3d50e588a689f6774ec39e28def5f7ea97703f993ca630390efc6bcd90d5d7bf1b57f1e8e48a55fe79476c0d0a477c
6
+ metadata.gz: c24b0a89a64dac20debb9cbac56c5e220975bc0665dd2f9e1d7e68c193bfcf9d2a25c9c6d3b3d15e61771d9196ac24539d1d242bb97debb510d621e68e7d2cc2
7
+ data.tar.gz: c5b6a04b1c0a29088947e0030bda475c46cda010734b1f193bd171f7b7be8bfc72c92011c92e30432061df1ab0f4a630a3c74afcf966ce0f16eb29283dd6844d
@@ -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/configuration'
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'
@@ -1,4 +1,3 @@
1
- require 'active_resource'
2
1
  require File.expand_path('../resources/base', __FILE__)
3
2
 
4
3
  module Mandao
@@ -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 || parsed['addressList']
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
- self.site = Mandao.config.api_endpoint
12
- self.format = Mandao.config.format
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 || parsed['document']
7
+ @elements = if attrs.present?
8
+ attrs
9
+ else
10
+ parsed['document']
11
+ end
10
12
  end
11
13
  end
12
14
 
@@ -1,3 +1,3 @@
1
1
  module Mandao
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -11,6 +11,14 @@ module ActiveResource
11
11
  end
12
12
  end
13
13
 
14
+ def extension
15
+ "xml"
16
+ end
17
+
18
+ def mime_type
19
+ "application/xml"
20
+ end
21
+
14
22
  end
15
23
  end
16
24
  end
@@ -14,7 +14,7 @@ describe Mandao::AddressList do
14
14
 
15
15
  it 'should return all address lists' do
16
16
  address_lists = Mandao::AddressList.all
17
- expect(address_lists).to be_present
17
+ expect(address_lists.count).to be > 0
18
18
  end
19
19
 
20
20
  it 'should create an address list' do
@@ -14,7 +14,7 @@ describe Mandao::Document do
14
14
 
15
15
  it 'should return all documents' do
16
16
  documents = Mandao::Document.all
17
- expect(documents).to be_present
17
+ expect(documents.count).to be > 0
18
18
  end
19
19
 
20
20
  it 'should create a document with a pdf' do
@@ -17,7 +17,7 @@ def stub_document_post
17
17
  end
18
18
 
19
19
  def stub_address_lists
20
- xml = "<addressLists><addressList><id>29547</id><ready>false</ready><total>0</total></addressList></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
@@ -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.3
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 00:00:00.000000000 Z
11
+ date: 2014-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource