adknowledge 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,5 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ coverage/*
6
+ .rbx/*
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-19mode
5
+ - rbx-19mode
data/Gemfile CHANGED
@@ -2,3 +2,15 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in adstation.gemspec
4
4
  gemspec
5
+
6
+ group :development, :test do
7
+ platforms :jruby do
8
+ gem 'gson'
9
+ gem 'libxml-jruby'
10
+ end
11
+
12
+ platforms :mri do
13
+ gem 'ox'
14
+ gem 'oj'
15
+ end
16
+ end
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  Adknowledge <a id='top'></a>
2
2
  ===========
3
+ [![Build Status](https://travis-ci.org/spiegela/adknowledge.png?branch=develop)](https://travis-ci.org/spiegela/adknowledge) [![Gem Version](https://badge.fury.io/rb/adknowledge.png)](http://badge.fury.io/rb/adknowledge) [![Dependency Status](https://gemnasium.com/spiegela/adknowledge.png)](https://gemnasium.com/spiegela/adknowledge) [![Code Climate](https://codeclimate.com/github/spiegela/adknowledge.png)](https://codeclimate.com/github/spiegela/adknowledge) [![Coverage Status](https://coveralls.io/repos/spiegela/adknowledge/badge.png?branch=master)](https://coveralls.io/r/spiegela/adknowledge)
3
4
 
4
5
  A very Ruby client library for [Adknowledge](http://www.adknowledge.com) APIs
5
6
 
@@ -19,15 +19,15 @@ Gem::Specification.new do |s|
19
19
  # specify any dependencies here; for example:
20
20
  s.add_development_dependency "pry"
21
21
  s.add_development_dependency "rspec"
22
- s.add_development_dependency "webmock", "1.10"
22
+ s.add_development_dependency "webmock"
23
23
  s.add_development_dependency "vcr"
24
+ s.add_development_dependency "coveralls"
24
25
  s.add_runtime_dependency "rake"
25
26
  s.add_runtime_dependency "activesupport"
26
- s.add_runtime_dependency "oj"
27
- s.add_runtime_dependency "ox"
28
27
  s.add_runtime_dependency "multi_xml"
28
+ s.add_runtime_dependency "multi_json"
29
+ s.add_runtime_dependency "nokogiri"
29
30
  s.add_runtime_dependency "addressable"
30
31
  s.add_runtime_dependency "faraday"
31
- s.add_runtime_dependency "faraday_middleware"
32
- s.add_runtime_dependency "faraday_middleware-parse_oj"
32
+ s.add_runtime_dependency "faraday_middleware-multi_json"
33
33
  end
@@ -1,8 +1,8 @@
1
1
  require 'faraday'
2
- require 'ox'
3
2
  require 'addressable/uri'
4
3
  require 'faraday_middleware/response/parse_xml'
5
4
  require 'active_support/core_ext/module/delegation'
5
+ require 'nokogiri'
6
6
 
7
7
  module Adknowledge
8
8
  class Integrated
@@ -47,14 +47,15 @@ module Adknowledge
47
47
  # @return [String] prepared XML request for recipient array
48
48
  def recipients= recipient_hashes
49
49
  @recipients = recipient_hashes
50
- doc = Ox::Document.new version: '1.0'
51
- req = Ox::Element.new 'request'
52
- doc << Ox::Instruct.new('xml version="1.0" encoding="UTF-8"') << req
53
- recipient_hashes.each do |recipient_hash|
54
- email_hash = recipient_hash.select{|x| VALID_FIELDS.include? x}
55
- req << email_xml(email_hash)
50
+ doc = Nokogiri::XML::Builder.new do |root|
51
+ root.request do |req|
52
+ recipient_hashes.each do |recipient_hash|
53
+ email_hash = recipient_hash.select{|x| VALID_FIELDS.include? x}
54
+ email_xml(email_hash, req)
55
+ end
56
+ end
56
57
  end
57
- @request = Ox.dump(doc, indent: 0, with_instruct: true).gsub(/\n/, '')
58
+ @request = doc.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML).gsub("\n", '')
58
59
  end
59
60
 
60
61
 
@@ -174,19 +175,15 @@ module Adknowledge
174
175
  uri.query
175
176
  end
176
177
 
177
- def email_xml email_hash
178
+ def email_xml email_hash, doc
178
179
  unless (MANDATORY_FIELDS - email_hash.keys).empty?
179
180
  raise ArgumentError, 'One or more mandatory fields were not submitted'
180
181
  end
181
- e = Ox::Element.new(:email)
182
- email_hash.each do |field, value|
183
- e << field_xml(field, value)
182
+ doc.email do |email|
183
+ email_hash.each do |field, value|
184
+ email.send(field, value)
185
+ end
184
186
  end
185
- e
186
- end
187
-
188
- def field_xml field, value
189
- Ox::Element.new(field) << value.to_s
190
187
  end
191
188
 
192
189
  end
@@ -1,6 +1,6 @@
1
1
  require 'faraday'
2
2
  require 'faraday_middleware'
3
- require 'faraday_middleware/parse_oj'
3
+ require 'faraday_middleware/multi_json'
4
4
  require 'active_support/core_ext/module/delegation'
5
5
 
6
6
  module Adknowledge
@@ -66,11 +66,7 @@ module Adknowledge
66
66
  # @param [Array] selection(s)
67
67
  # @return [Adknowledge::Performance] query object
68
68
  def select *selection
69
- selection = selection.map{|x| x.to_sym} # handle strings & symbols equally
70
- unless (selection - VALID_MEASURES).empty?
71
- raise ArgumentError, 'Invalid measurement selection'
72
- end
73
- @measures.merge! Hash[selection.zip([1] * selection.count)]
69
+ @measures.merge! paramerize(selection, VALID_MEASURES, 'Invalid measurement selection')
74
70
  self
75
71
  end
76
72
 
@@ -79,11 +75,7 @@ module Adknowledge
79
75
  # @param [Array] grouping(s)
80
76
  # @return [Adknowledge::Performance] query object
81
77
  def group_by *groupings
82
- groupings = groupings.map{|x| x.to_sym} # handle strings & symbols equally
83
- unless (groupings - VALID_DIMENSIONS).empty?
84
- raise ArgumentError, 'Invalid dimension grouping'
85
- end
86
- @dimensions.merge! Hash[groupings.zip([1] * groupings.count)]
78
+ @dimensions.merge! paramerize(groupings, VALID_DIMENSIONS, 'Invalid dimension group')
87
79
  self
88
80
  end
89
81
 
@@ -129,10 +121,7 @@ module Adknowledge
129
121
  # @param [Boolean] full
130
122
  # @return [Adknowledge::Performance] query object
131
123
  def full full
132
- unless !!full == full #Boolean check
133
- raise ArgumentError, 'Full option must be a boolean'
134
- end
135
- @options[:full] = full ? '1' : '0'
124
+ @options[:full] = booleanize 'Full', full
136
125
  self
137
126
  end
138
127
 
@@ -141,10 +130,7 @@ module Adknowledge
141
130
  # @param [Boolean] nocache
142
131
  # @return [Adknowledge::Performance] query object
143
132
  def nocache nocache
144
- unless !!nocache == nocache #Boolean check
145
- raise ArgumentError, 'NoCache option must be a boolean'
146
- end
147
- @options[:nocache] = nocache ? '1' : '0'
133
+ @options[:nocache] = booleanize 'NoCache', nocache
148
134
  self
149
135
  end
150
136
 
@@ -153,10 +139,7 @@ module Adknowledge
153
139
  # @param [Boolean] display_all
154
140
  # @return [Adknowledge::Performance] query object
155
141
  def display_all display_all
156
- unless !!display_all == display_all #Boolean check
157
- raise ArgumentError, "display_all option must be a boolean"
158
- end
159
- @options[:all] = display_all ? '1' : '0'
142
+ @options[:all] = booleanize 'DisplayAll', display_all
160
143
  self
161
144
  end
162
145
 
@@ -223,11 +206,26 @@ module Adknowledge
223
206
 
224
207
  def conn
225
208
  @conn ||= Faraday.new(:url => URL) do |b|
226
- b.response :oj
209
+ b.response :multi_json
227
210
  b.adapter Faraday.default_adapter
228
211
  end
229
212
  end
230
213
 
214
+ def paramerize array, valid, error_str
215
+ array = array.map{|x| x.to_sym} # handle strings & symbols equally
216
+ unless (array - valid).empty?
217
+ raise ArgumentError, error_str
218
+ end
219
+ Hash[array.zip([1] * array.count)]
220
+ end
221
+
222
+ def booleanize name, value
223
+ unless !!value == value #Boolean check
224
+ raise ArgumentError, "#{name} option must be a boolean"
225
+ end
226
+ value ? '1' : '0'
227
+ end
228
+
231
229
  def valid_pivot_values
232
230
  dimensions.keys + ['*']
233
231
  end
@@ -1,3 +1,3 @@
1
1
  module Adknowledge
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -23,7 +23,7 @@ describe Adknowledge::Integrated do
23
23
 
24
24
  let :request_xml do
25
25
  %q[
26
- <?xml version="1.0" encoding="UTF-8"?>
26
+ <?xml version="1.0"?>
27
27
  <request>
28
28
  <email>
29
29
  <recipient>004c58927df600d73d58c817bafc2155</recipient>
@@ -4,6 +4,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
4
4
  require 'adknowledge'
5
5
  require 'rspec'
6
6
  require 'vcr'
7
+ require 'coveralls'
7
8
 
8
9
  VCR.configure do |c|
9
10
  c.hook_into :webmock
@@ -14,3 +15,5 @@ VCR.configure do |c|
14
15
  match_requests_on: [ :method ]
15
16
  }
16
17
  end
18
+
19
+ Coveralls.wear!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adknowledge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -48,17 +48,17 @@ dependencies:
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - '='
51
+ - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
- version: '1.10'
53
+ version: '0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - '='
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
- version: '1.10'
61
+ version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: vcr
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -76,14 +76,14 @@ dependencies:
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  - !ruby/object:Gem::Dependency
79
- name: rake
79
+ name: coveralls
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
83
  - - ! '>='
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
- type: :runtime
86
+ type: :development
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  none: false
@@ -92,7 +92,7 @@ dependencies:
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  - !ruby/object:Gem::Dependency
95
- name: activesupport
95
+ name: rake
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
@@ -108,7 +108,7 @@ dependencies:
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  - !ruby/object:Gem::Dependency
111
- name: oj
111
+ name: activesupport
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
@@ -124,7 +124,7 @@ dependencies:
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  - !ruby/object:Gem::Dependency
127
- name: ox
127
+ name: multi_xml
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
@@ -140,7 +140,7 @@ dependencies:
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  - !ruby/object:Gem::Dependency
143
- name: multi_xml
143
+ name: multi_json
144
144
  requirement: !ruby/object:Gem::Requirement
145
145
  none: false
146
146
  requirements:
@@ -156,7 +156,7 @@ dependencies:
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
158
  - !ruby/object:Gem::Dependency
159
- name: addressable
159
+ name: nokogiri
160
160
  requirement: !ruby/object:Gem::Requirement
161
161
  none: false
162
162
  requirements:
@@ -172,7 +172,7 @@ dependencies:
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  - !ruby/object:Gem::Dependency
175
- name: faraday
175
+ name: addressable
176
176
  requirement: !ruby/object:Gem::Requirement
177
177
  none: false
178
178
  requirements:
@@ -188,7 +188,7 @@ dependencies:
188
188
  - !ruby/object:Gem::Version
189
189
  version: '0'
190
190
  - !ruby/object:Gem::Dependency
191
- name: faraday_middleware
191
+ name: faraday
192
192
  requirement: !ruby/object:Gem::Requirement
193
193
  none: false
194
194
  requirements:
@@ -204,7 +204,7 @@ dependencies:
204
204
  - !ruby/object:Gem::Version
205
205
  version: '0'
206
206
  - !ruby/object:Gem::Dependency
207
- name: faraday_middleware-parse_oj
207
+ name: faraday_middleware-multi_json
208
208
  requirement: !ruby/object:Gem::Requirement
209
209
  none: false
210
210
  requirements:
@@ -227,6 +227,7 @@ extensions: []
227
227
  extra_rdoc_files: []
228
228
  files:
229
229
  - .gitignore
230
+ - .travis.yml
230
231
  - Gemfile
231
232
  - README.md
232
233
  - Rakefile
@@ -256,18 +257,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
256
257
  - - ! '>='
257
258
  - !ruby/object:Gem::Version
258
259
  version: '0'
259
- segments:
260
- - 0
261
- hash: 387899590965844068
262
260
  required_rubygems_version: !ruby/object:Gem::Requirement
263
261
  none: false
264
262
  requirements:
265
263
  - - ! '>='
266
264
  - !ruby/object:Gem::Version
267
265
  version: '0'
268
- segments:
269
- - 0
270
- hash: 387899590965844068
271
266
  requirements: []
272
267
  rubyforge_project:
273
268
  rubygems_version: 1.8.24
@@ -282,3 +277,4 @@ test_files:
282
277
  - spec/cassettes/map_single_success.yml
283
278
  - spec/cassettes/performance.yml
284
279
  - spec/spec_helper.rb
280
+ has_rdoc: