mozenda 0.0.5
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 +7 -0
- data/.gitignore +18 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +99 -0
- data/Rakefile +1 -0
- data/lib/mozenda.rb +25 -0
- data/lib/mozenda/configuration.rb +42 -0
- data/lib/mozenda/exception.rb +19 -0
- data/lib/mozenda/infrastructure.rb +7 -0
- data/lib/mozenda/infrastructure/connection.rb +47 -0
- data/lib/mozenda/infrastructure/file.rb +24 -0
- data/lib/mozenda/model.rb +8 -0
- data/lib/mozenda/model/agent.rb +18 -0
- data/lib/mozenda/model/base.rb +5 -0
- data/lib/mozenda/model/collection.rb +32 -0
- data/lib/mozenda/replacement_values.rb +16 -0
- data/lib/mozenda/request.rb +10 -0
- data/lib/mozenda/request/agent_run.rb +45 -0
- data/lib/mozenda/request/base.rb +45 -0
- data/lib/mozenda/request/collection_add_item.rb +19 -0
- data/lib/mozenda/request/collection_add_item_bulk.rb +28 -0
- data/lib/mozenda/request/collection_clear.rb +15 -0
- data/lib/mozenda/response.rb +9 -0
- data/lib/mozenda/response/agent_run.rb +17 -0
- data/lib/mozenda/response/base.rb +40 -0
- data/lib/mozenda/response/collection_add_item.rb +13 -0
- data/lib/mozenda/response/collection_clear.rb +9 -0
- data/lib/mozenda/version.rb +5 -0
- data/mozenda.gemspec +33 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f72b544b775f33f4aa815e063a6cc9b327d536a5
|
4
|
+
data.tar.gz: 06f75ca0f03e18e44ae5e05930649dc0dcf9e757
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 46d8cf16dbb426c28c21574c187199d137b2e35ee000104904308f30ec05065ec4528952f818bacbbf8e2a6cb3955871a597aae23325b738f121c88b166f21be
|
7
|
+
data.tar.gz: bc20b926897cccca1edc659d800e2be3a6527a15cad482305ae8f27e9953f1878390b458fc012394471fcba6fd749cff533308cf9d248d7d2714cacfd7cf8c93
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Piotr Woloszun
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# mozenda
|
2
|
+
|
3
|
+
*mozenda* is a ruby gem for interacting with [mozenda](https://www.mozenda.com/) via their [api](https://www.mozenda.com/api).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'mozenda'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mozenda
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
*mozenda* requires a WebServiceKey to be configured. The following code configures *mozenda* (*config/initializers* is a good place for this).
|
22
|
+
```ruby
|
23
|
+
Mozenda.configuration do |config|
|
24
|
+
config.web_service_key = "your-mozenda-web-service-key"
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
To add single item to Collection:
|
29
|
+
```ruby
|
30
|
+
collection_id = 1046
|
31
|
+
collection = Mozenda::Model::Collection.new(collection_id)
|
32
|
+
collection.add_item({
|
33
|
+
"Field1" => "qq",
|
34
|
+
"Field3" => 123
|
35
|
+
})
|
36
|
+
```
|
37
|
+
|
38
|
+
To add many items to Collection from XML file:
|
39
|
+
```ruby
|
40
|
+
path_to_xml_file = Pathname.new("./bulk_test.xml").realpath.to_s
|
41
|
+
collection_id = 1046
|
42
|
+
collection = Mozenda::Model::Collection.new(collection_id)
|
43
|
+
collection.add_items_from_file(path_to_xml_file)
|
44
|
+
```
|
45
|
+
|
46
|
+
To clear Collection:
|
47
|
+
```ruby
|
48
|
+
collection_id = 1046
|
49
|
+
collection = Mozenda::Model::Collection.new(collection_id)
|
50
|
+
collection.clear
|
51
|
+
```
|
52
|
+
|
53
|
+
To run Agent:
|
54
|
+
```ruby
|
55
|
+
agent_id = 1050
|
56
|
+
agent = Mozenda::Model::Agent.new(agent_id)
|
57
|
+
agent.run
|
58
|
+
```
|
59
|
+
|
60
|
+
To run Agent with optional params:
|
61
|
+
```ruby
|
62
|
+
agent_id = 1050
|
63
|
+
agent = Mozenda::Model::Agent.new(agent_id)
|
64
|
+
agent.run({
|
65
|
+
"MyParam1" => 123,
|
66
|
+
"my-other-param" => "imba!"
|
67
|
+
})
|
68
|
+
```
|
69
|
+
|
70
|
+
To run Agent with Job.StatusUrl:
|
71
|
+
```ruby
|
72
|
+
agent_id = 1050
|
73
|
+
agent = Mozenda::Model::Agent.new(agent_id)
|
74
|
+
optional_params = {}
|
75
|
+
agent.run(optional_params, {
|
76
|
+
:status_url => "http://localhost:3000/some/path",
|
77
|
+
:replacement_values => {
|
78
|
+
:job_id => Mozenda::ReplacementValues::JOB_ID,
|
79
|
+
:job_status => Mozenda::ReplacementValues::JOB_STATUS,
|
80
|
+
:job_ended => Mozenda::ReplacementValues::JOB_ENDED
|
81
|
+
}
|
82
|
+
})
|
83
|
+
```
|
84
|
+
|
85
|
+
## TODO
|
86
|
+
* Implement requests-per-minute limit.
|
87
|
+
* Implement other Mozenda services
|
88
|
+
|
89
|
+
## License
|
90
|
+
|
91
|
+
This software is relased under the [MIT license](LICENSE.md).
|
92
|
+
|
93
|
+
## Contributing
|
94
|
+
|
95
|
+
1. Fork it
|
96
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
97
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
98
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
99
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/mozenda.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'uri'
|
3
|
+
require 'pathname'
|
4
|
+
require 'active_support/core_ext/string/inflections'
|
5
|
+
require 'faraday'
|
6
|
+
require 'nori'
|
7
|
+
|
8
|
+
require "mozenda/version"
|
9
|
+
require "mozenda/exception"
|
10
|
+
require "mozenda/configuration"
|
11
|
+
require "mozenda/replacement_values"
|
12
|
+
require "mozenda/infrastructure"
|
13
|
+
require "mozenda/request"
|
14
|
+
require "mozenda/response"
|
15
|
+
require "mozenda/model"
|
16
|
+
|
17
|
+
module Mozenda
|
18
|
+
|
19
|
+
def self.configuration &block
|
20
|
+
config = Mozenda::Configuration.instance
|
21
|
+
yield(config) if block
|
22
|
+
config
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Mozenda
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
include ::Singleton
|
5
|
+
|
6
|
+
REQUIRED_OPTIONS = [:web_service_key].freeze
|
7
|
+
OPTIONAL_OPTIONS = [:base_uri, :service, :rate_limit].freeze
|
8
|
+
ALL_OPTIONS = REQUIRED_OPTIONS + OPTIONAL_OPTIONS
|
9
|
+
|
10
|
+
attr_reader :options
|
11
|
+
|
12
|
+
ALL_OPTIONS.each do |option_name|
|
13
|
+
|
14
|
+
define_method "#{option_name}=" do |option_value|
|
15
|
+
@options[option_name] = option_value
|
16
|
+
end
|
17
|
+
|
18
|
+
define_method option_name do
|
19
|
+
raise Mozenda::ConfigurationException.new("missing required option: #{option_name}") if required_option_undefined?(option_name)
|
20
|
+
options[option_name]
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
DEFAULT_OPTIONS = {
|
28
|
+
:base_uri => "https://api.mozenda.com/rest",
|
29
|
+
:service => 'Mozenda10',
|
30
|
+
:rate_limit => 28.0 / 60.0
|
31
|
+
}.freeze
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
@options = DEFAULT_OPTIONS.dup
|
35
|
+
end
|
36
|
+
|
37
|
+
def required_option_undefined? option_sym
|
38
|
+
REQUIRED_OPTIONS.include?(option_sym) && options[option_sym].nil?
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mozenda
|
2
|
+
class Exception < ::Exception
|
3
|
+
end
|
4
|
+
|
5
|
+
class ConfigurationException < Exception
|
6
|
+
end
|
7
|
+
|
8
|
+
class MissingMethodException < Exception
|
9
|
+
end
|
10
|
+
|
11
|
+
class InvalidRequestException < Exception
|
12
|
+
end
|
13
|
+
|
14
|
+
class ResponseTypeException < Exception
|
15
|
+
end
|
16
|
+
|
17
|
+
class InvalidFileFormatException < Exception
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Mozenda::Infrastructure
|
2
|
+
class Connection
|
3
|
+
|
4
|
+
include ::Singleton
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
config = Mozenda::Configuration.instance
|
8
|
+
default_params = {
|
9
|
+
"WebServiceKey" => config.web_service_key,
|
10
|
+
"Service" => config.service
|
11
|
+
}
|
12
|
+
@client = ::Faraday.new(url: config.base_uri, params: default_params)
|
13
|
+
@multipart_client = ::Faraday.new(url: config.base_uri, params: default_params) do |builder|
|
14
|
+
builder.request :multipart
|
15
|
+
builder.request :url_encoded
|
16
|
+
builder.adapter :net_http
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def get params
|
21
|
+
send_request(:get, params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def post params
|
25
|
+
send_request(:post, params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def multipart params, file_path
|
29
|
+
file = ::Faraday::UploadIO.new(file_path, 'application/xml')
|
30
|
+
@multipart_client.post do |request|
|
31
|
+
request.params.merge!(params)
|
32
|
+
request.body = {
|
33
|
+
"file" => file
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def send_request type, params
|
41
|
+
@client.send(type) do |request|
|
42
|
+
request.params.merge!(params)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Mozenda::Infrastructure
|
2
|
+
class File
|
3
|
+
|
4
|
+
def initialize file_path
|
5
|
+
@path = ::Pathname.new(file_path)
|
6
|
+
end
|
7
|
+
|
8
|
+
def validate!
|
9
|
+
item_list = to_h["ItemList"]
|
10
|
+
raise InvalidFileFormatException.new("Missing XML root tag: 'ItemList'") if item_list.nil?
|
11
|
+
items = item_list["Item"]
|
12
|
+
raise InvalidFileFormatException.new("Missing XML tag: 'Item'") if items.nil?
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_h
|
16
|
+
@hash ||= ::Nori.new.parse(content)
|
17
|
+
end
|
18
|
+
|
19
|
+
def content
|
20
|
+
@content ||= @path.read
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Mozenda::Model
|
2
|
+
class Agent < Mozenda::Model::Base
|
3
|
+
|
4
|
+
def initialize agent_id
|
5
|
+
@id = agent_id
|
6
|
+
end
|
7
|
+
|
8
|
+
def run params = {}, job_params = {}
|
9
|
+
request = Mozenda::Request::AgentRun.new({
|
10
|
+
:agent_id => @id,
|
11
|
+
:params => params,
|
12
|
+
:job_params => job_params
|
13
|
+
})
|
14
|
+
request.send!
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Mozenda::Model
|
2
|
+
class Collection < Mozenda::Model::Base
|
3
|
+
|
4
|
+
def initialize collection_id
|
5
|
+
@id = collection_id
|
6
|
+
end
|
7
|
+
|
8
|
+
def add_item fields
|
9
|
+
request = Mozenda::Request::CollectionAddItem.new({
|
10
|
+
:collection_id => @id,
|
11
|
+
:fields => fields
|
12
|
+
})
|
13
|
+
request.send!
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_items_from_file file_path
|
17
|
+
request = Mozenda::Request::CollectionAddItemBulk.new({
|
18
|
+
:collection_id => @id,
|
19
|
+
:file_path => file_path
|
20
|
+
})
|
21
|
+
request.send!
|
22
|
+
end
|
23
|
+
|
24
|
+
def clear
|
25
|
+
request = Mozenda::Request::CollectionClear.new({
|
26
|
+
:collection_id => @id
|
27
|
+
})
|
28
|
+
request.send!
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Mozenda::ReplacementValues
|
2
|
+
|
3
|
+
AGENT_ID = "AgentID"
|
4
|
+
AGENT_NAME = "Agent.Name"
|
5
|
+
AGENT_DESCRIPTION = "Agent.Description"
|
6
|
+
AGENT_DOMAIN = "Agent.Domain"
|
7
|
+
JOB_ID = "JobID"
|
8
|
+
JOB_STATUS = "Job.Status"
|
9
|
+
JOB_CREATED = "Job.Created"
|
10
|
+
JOB_ENDED = "Job.Ended"
|
11
|
+
JOB_NAME = "Job.Name"
|
12
|
+
JOB_DESCRIPTION = "Job.Description"
|
13
|
+
|
14
|
+
ALL = [AGENT_ID, AGENT_NAME, AGENT_DESCRIPTION, AGENT_DOMAIN, JOB_ID, JOB_STATUS, JOB_CREATED, JOB_ENDED, JOB_NAME, JOB_DESCRIPTION].freeze
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Mozenda
|
2
|
+
module Request
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'mozenda/request/base'
|
7
|
+
require 'mozenda/request/agent_run'
|
8
|
+
require 'mozenda/request/collection_add_item'
|
9
|
+
require 'mozenda/request/collection_add_item_bulk'
|
10
|
+
require 'mozenda/request/collection_clear'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Mozenda::Request
|
2
|
+
class AgentRun < Mozenda::Request::Base
|
3
|
+
|
4
|
+
def initialize options
|
5
|
+
super
|
6
|
+
put_additional_param("AgentID", options[:agent_id])
|
7
|
+
params = options[:params] || {}
|
8
|
+
params.each_pair do |name, value|
|
9
|
+
put_additional_param("AgentParameter.#{name}", value)
|
10
|
+
end
|
11
|
+
job_params = options[:job_params] || {}
|
12
|
+
put_additional_param("Job.StatusUrl", format_status_url(job_params)) unless job_params.empty?
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
OPERATION = "Agent.Run"
|
18
|
+
REQUIRED_PARAMS = ["AgentID", "Operation"].freeze
|
19
|
+
|
20
|
+
def include_status_url? params
|
21
|
+
status_url = params[:status_url] || ""
|
22
|
+
replacement_values = params[:replacement_values] || {}
|
23
|
+
!(status_url.empty? || replacement_values.empty?)
|
24
|
+
end
|
25
|
+
|
26
|
+
def format_status_url params
|
27
|
+
status_url = params[:status_url] || ""
|
28
|
+
replacement_values = params[:replacement_values] || {}
|
29
|
+
unless status_url.empty? || replacement_values.empty?
|
30
|
+
uri = URI(status_url)
|
31
|
+
params = URI.decode_www_form(uri.query || [])
|
32
|
+
replacement_values.each_pair do |name, value|
|
33
|
+
params << [name, value]
|
34
|
+
end
|
35
|
+
uri.query = URI.encode_www_form(params)
|
36
|
+
status_url = uri.to_s
|
37
|
+
Mozenda::ReplacementValues::ALL.each do |replacement_value|
|
38
|
+
status_url = status_url.gsub(replacement_value, "%#{replacement_value}%")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
status_url
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Mozenda::Request
|
2
|
+
class Base
|
3
|
+
|
4
|
+
def initialize options
|
5
|
+
@connection = Mozenda::Infrastructure::Connection.instance
|
6
|
+
end
|
7
|
+
|
8
|
+
def send! method = :post
|
9
|
+
validate!
|
10
|
+
response = @connection.send(method, additional_params)
|
11
|
+
response_class.new(response)
|
12
|
+
end
|
13
|
+
|
14
|
+
def validate!
|
15
|
+
required_params.each do |param_name|
|
16
|
+
raise Mozenda::InvalidRequestException.new("Request #{operation}: required param '#{param_name}' is undefined") if additional_params[param_name].nil?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def response_class
|
23
|
+
class_name = operation.gsub(/\./, "")
|
24
|
+
full_class_name = "Mozenda::Response::#{class_name}"
|
25
|
+
full_class_name.constantize
|
26
|
+
end
|
27
|
+
|
28
|
+
def required_params
|
29
|
+
self.class.const_get(:REQUIRED_PARAMS)
|
30
|
+
end
|
31
|
+
|
32
|
+
def operation
|
33
|
+
self.class.const_get(:OPERATION)
|
34
|
+
end
|
35
|
+
|
36
|
+
def additional_params
|
37
|
+
@additional_params ||= {"Operation" => operation}
|
38
|
+
end
|
39
|
+
|
40
|
+
def put_additional_param key, value
|
41
|
+
additional_params[key] = value
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mozenda::Request
|
2
|
+
class CollectionAddItem < Mozenda::Request::Base
|
3
|
+
|
4
|
+
def initialize options
|
5
|
+
super
|
6
|
+
put_additional_param("CollectionID", options[:collection_id])
|
7
|
+
fields = options[:fields] || {}
|
8
|
+
fields.each_pair do |name, value|
|
9
|
+
put_additional_param("Field.#{name}", value)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
OPERATION = "Collection.AddItem"
|
16
|
+
REQUIRED_PARAMS = ["CollectionID", "Operation"].freeze
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Mozenda::Request
|
2
|
+
class CollectionAddItemBulk < Mozenda::Request::CollectionAddItem
|
3
|
+
|
4
|
+
def initialize options
|
5
|
+
super
|
6
|
+
@file_path = options[:file_path]
|
7
|
+
end
|
8
|
+
|
9
|
+
def send!
|
10
|
+
validate!
|
11
|
+
response = @connection.multipart(additional_params, @file_path)
|
12
|
+
response_class.new(response)
|
13
|
+
end
|
14
|
+
|
15
|
+
def validate!
|
16
|
+
super
|
17
|
+
file = Mozenda::Infrastructure::File.new(@file_path)
|
18
|
+
file.validate!
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def validate_xml_content!
|
24
|
+
# TODO
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Mozenda::Request
|
2
|
+
class CollectionClear < Mozenda::Request::Base
|
3
|
+
|
4
|
+
def initialize options
|
5
|
+
super
|
6
|
+
put_additional_param("CollectionID", options[:collection_id])
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
OPERATION = "Collection.Clear"
|
12
|
+
REQUIRED_PARAMS = ["CollectionID", "Operation"].freeze
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Mozenda::Response
|
2
|
+
class Base
|
3
|
+
|
4
|
+
attr_reader :response
|
5
|
+
|
6
|
+
def initialize http_response
|
7
|
+
@response = http_response
|
8
|
+
@xml = @response.body
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid?
|
12
|
+
!body_hash.nil?
|
13
|
+
end
|
14
|
+
|
15
|
+
def success?
|
16
|
+
return false unless valid?
|
17
|
+
result = body_hash["Result"] || ""
|
18
|
+
result.downcase == "success"
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_xml
|
22
|
+
@xml
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_h
|
26
|
+
@hash ||= ::Nori.new.parse(@xml)
|
27
|
+
end
|
28
|
+
|
29
|
+
def name
|
30
|
+
self.class.const_get(:NAME)
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
|
35
|
+
def body_hash
|
36
|
+
to_h[name]
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/mozenda.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mozenda/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mozenda"
|
8
|
+
spec.version = Mozenda::VERSION
|
9
|
+
spec.authors = ["Piotr Woloszun"]
|
10
|
+
spec.email = ["piotr.woloszun@gmail.com"]
|
11
|
+
spec.description = %q{Mozenda API gem}
|
12
|
+
spec.summary = %q{Mozenda API gem}
|
13
|
+
spec.homepage = "https://github.com/pwoloszun/mozenda"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
|
22
|
+
{
|
23
|
+
"bundler" => "~> 1.3",
|
24
|
+
'activesupport' => '~> 4.1.1',
|
25
|
+
"faraday" => "~> 0.9.0",
|
26
|
+
"nori" => "~> 2.3.0",
|
27
|
+
'nokogiri' => '~> 1.6.2.1'
|
28
|
+
}.each_pair do |name, version|
|
29
|
+
spec.add_development_dependency(name, version)
|
30
|
+
end
|
31
|
+
|
32
|
+
spec.add_development_dependency "rake"
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mozenda
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Piotr Woloszun
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.1.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.1.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.9.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nori
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.3.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.3.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: nokogiri
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.6.2.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.6.2.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Mozenda API gem
|
98
|
+
email:
|
99
|
+
- piotr.woloszun@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- lib/mozenda.rb
|
110
|
+
- lib/mozenda/configuration.rb
|
111
|
+
- lib/mozenda/exception.rb
|
112
|
+
- lib/mozenda/infrastructure.rb
|
113
|
+
- lib/mozenda/infrastructure/connection.rb
|
114
|
+
- lib/mozenda/infrastructure/file.rb
|
115
|
+
- lib/mozenda/model.rb
|
116
|
+
- lib/mozenda/model/agent.rb
|
117
|
+
- lib/mozenda/model/base.rb
|
118
|
+
- lib/mozenda/model/collection.rb
|
119
|
+
- lib/mozenda/replacement_values.rb
|
120
|
+
- lib/mozenda/request.rb
|
121
|
+
- lib/mozenda/request/agent_run.rb
|
122
|
+
- lib/mozenda/request/base.rb
|
123
|
+
- lib/mozenda/request/collection_add_item.rb
|
124
|
+
- lib/mozenda/request/collection_add_item_bulk.rb
|
125
|
+
- lib/mozenda/request/collection_clear.rb
|
126
|
+
- lib/mozenda/response.rb
|
127
|
+
- lib/mozenda/response/agent_run.rb
|
128
|
+
- lib/mozenda/response/base.rb
|
129
|
+
- lib/mozenda/response/collection_add_item.rb
|
130
|
+
- lib/mozenda/response/collection_clear.rb
|
131
|
+
- lib/mozenda/version.rb
|
132
|
+
- mozenda.gemspec
|
133
|
+
homepage: https://github.com/pwoloszun/mozenda
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.0.3
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: Mozenda API gem
|
157
|
+
test_files: []
|