office_autopilot 0.0.1
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.
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +44 -0
- data/Rakefile +8 -0
- data/lib/office_autopilot/client/contacts.rb +27 -0
- data/lib/office_autopilot/client.rb +60 -0
- data/lib/office_autopilot/version.rb +3 -0
- data/lib/office_autopilot.rb +1 -0
- data/office_autopilot.gemspec +30 -0
- data/spec/data/contacts_search_multiple_response.xml +198 -0
- data/spec/data/contacts_search_single_response.xml +68 -0
- data/spec/office_autopilot/client/contacts_spec.rb +71 -0
- data/spec/office_autopilot/client_spec.rb +90 -0
- data/spec/spec_helper.rb +24 -0
- metadata +141 -0
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Prashant Nadarajan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
The OfficeAutopilot Ruby Gem
|
2
|
+
============================
|
3
|
+
A Ruby wrapper for the OfficeAutopilot API
|
4
|
+
|
5
|
+
Installation
|
6
|
+
------------
|
7
|
+
gem install office_autopilot
|
8
|
+
|
9
|
+
Usage Examples
|
10
|
+
--------------
|
11
|
+
require "rubygems"
|
12
|
+
require "office_autopilot"
|
13
|
+
|
14
|
+
oap = OfficeAutopilot::Client.new(:api_id => 'xxx', :api_key => 'yyy')
|
15
|
+
|
16
|
+
# Search Contacts
|
17
|
+
puts oap.contacts_search(:field => 'E-Mail', :op => 'e', :value => 'jimbo@example.com')
|
18
|
+
=> [ { :id => 7, :first_name => 'Jimbo', :last_name => 'Watunusi', :email => 'jimbo@example.com' } ]
|
19
|
+
|
20
|
+
Documentation
|
21
|
+
-------------
|
22
|
+
[OfficeAutopilot API Docs](http://wiki.sendpepper.com/w/page/19528683/API-Documentation)
|
23
|
+
|
24
|
+
Todo
|
25
|
+
----
|
26
|
+
|
27
|
+
* support ALL API calls
|
28
|
+
* allow returning all possible contact details instead of the current subset
|
29
|
+
|
30
|
+
Submitting a Pull Request
|
31
|
+
-------------------------
|
32
|
+
1. Fork the project.
|
33
|
+
2. Create a topic branch.
|
34
|
+
3. Implement your feature or bug fix.
|
35
|
+
4. Add documentation for your feature or bug fix.
|
36
|
+
5. Add specs for your feature or bug fix.
|
37
|
+
6. Run <tt>bundle exec rake spec</tt>. If your changes are not 100% covered, go back to step 5.
|
38
|
+
7. Commit and push your changes.
|
39
|
+
8. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
|
40
|
+
|
41
|
+
Copyright
|
42
|
+
---------
|
43
|
+
Copyright (c) 2011 Prashant Nadarajan.
|
44
|
+
See [LICENSE](https://github.com/prashantrajan/office_autopilot/blob/master/LICENSE) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module OfficeAutopilot
|
2
|
+
class Client
|
3
|
+
|
4
|
+
module Contacts
|
5
|
+
|
6
|
+
CONTACTS_ENDPOINT = '/cdata.php'
|
7
|
+
|
8
|
+
def contacts_search(options = {})
|
9
|
+
xml = xml_for_search(options)
|
10
|
+
response = self.class.post(CONTACTS_ENDPOINT, :body => {'reqType' => 'search', 'data' => xml}.merge(auth))
|
11
|
+
|
12
|
+
contacts = []
|
13
|
+
xml = Nokogiri::XML(response)
|
14
|
+
xml.css('result contact').each do |node|
|
15
|
+
contacts << {
|
16
|
+
:id => node['id'].to_i,
|
17
|
+
:first_name => node.at_css("Group_Tag[name='Contact Information'] field[name='First Name']").text,
|
18
|
+
:last_name => node.at_css("Group_Tag[name='Contact Information'] field[name='Last Name']").text,
|
19
|
+
:email => node.at_css("Group_Tag[name='Contact Information'] field[name='E-Mail']").text
|
20
|
+
}
|
21
|
+
end
|
22
|
+
contacts
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'builder'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
|
6
|
+
require File.expand_path('../client/contacts', __FILE__)
|
7
|
+
|
8
|
+
|
9
|
+
module OfficeAutopilot
|
10
|
+
class Client
|
11
|
+
|
12
|
+
include HTTParty
|
13
|
+
|
14
|
+
include OfficeAutopilot::Client::Contacts
|
15
|
+
|
16
|
+
base_uri 'http://api.moon-ray.com'
|
17
|
+
format :plain
|
18
|
+
|
19
|
+
|
20
|
+
def initialize(options)
|
21
|
+
@api = {
|
22
|
+
:api_id => options[:api_id],
|
23
|
+
:api_key => options[:api_key]
|
24
|
+
}
|
25
|
+
|
26
|
+
raise ArgumentError, "Missing required parameter: api_id" if @api[:api_id].nil?
|
27
|
+
raise ArgumentError, "Missing required parameter: api_key" if @api[:api_key].nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
def api_id
|
31
|
+
@api[:api_id]
|
32
|
+
end
|
33
|
+
|
34
|
+
def api_key
|
35
|
+
@api[:api_key]
|
36
|
+
end
|
37
|
+
|
38
|
+
def auth
|
39
|
+
{ 'Appid' => api_id, 'Key' => api_key }
|
40
|
+
end
|
41
|
+
|
42
|
+
def xml_for_search(options)
|
43
|
+
if options.is_a?(Hash)
|
44
|
+
options = [ options ]
|
45
|
+
end
|
46
|
+
|
47
|
+
xml = Builder::XmlMarkup.new
|
48
|
+
xml.search do
|
49
|
+
options.each do |option|
|
50
|
+
xml.equation do
|
51
|
+
xml.field option[:field]
|
52
|
+
xml.op option[:op]
|
53
|
+
xml.value option[:value]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'office_autopilot/client'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "office_autopilot/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
|
7
|
+
s.add_development_dependency('rake', '~> 0.8')
|
8
|
+
s.add_development_dependency('rspec', '~> 2.5')
|
9
|
+
s.add_development_dependency('webmock', '~> 1.6')
|
10
|
+
|
11
|
+
s.add_runtime_dependency('httparty', '~> 0.7')
|
12
|
+
s.add_runtime_dependency('builder', '~> 3.0')
|
13
|
+
s.add_runtime_dependency('nokogiri', '~> 1.4')
|
14
|
+
|
15
|
+
s.name = "office_autopilot"
|
16
|
+
s.version = OfficeAutopilot::VERSION
|
17
|
+
s.platform = Gem::Platform::RUBY
|
18
|
+
s.authors = ["Prashant Nadarajan"]
|
19
|
+
s.email = ["prashant.nadarajan@gmail.com"]
|
20
|
+
s.homepage = "https://github.com/prashantrajan/office_autopilot"
|
21
|
+
s.summary = %q{Ruby wrapper for the OfficeAutopilot API}
|
22
|
+
s.description = %q{A Ruby wrapper for the OfficeAutopilot API}
|
23
|
+
|
24
|
+
s.rubyforge_project = "office_autopilot"
|
25
|
+
|
26
|
+
s.files = `git ls-files`.split("\n")
|
27
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
28
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
29
|
+
s.require_paths = ["lib"]
|
30
|
+
end
|
@@ -0,0 +1,198 @@
|
|
1
|
+
<result>
|
2
|
+
<contact id='8' date='1299674533' dlm='1299674554' score='0.00' purl='bobby' bulk_mail='1'>
|
3
|
+
<Group_Tag name='Contact Information'>
|
4
|
+
<field name="First Name">bobby</field>
|
5
|
+
<field name="Last Name">brown</field>
|
6
|
+
<field name="E-Mail">bobby@example.com</field>
|
7
|
+
<field name="Home Phone"/>
|
8
|
+
<field name="Title"/>
|
9
|
+
<field name="Office Phone"/>
|
10
|
+
<field name="Cell Phone"/>
|
11
|
+
<field name="Fax"/>
|
12
|
+
<field name="Address"/>
|
13
|
+
<field name="Company"/>
|
14
|
+
<field name="Address 2"/>
|
15
|
+
<field name="City"/>
|
16
|
+
<field name="State"/>
|
17
|
+
<field name="Zip Code"/>
|
18
|
+
<field name="Website "/>
|
19
|
+
<field name="Country"/>
|
20
|
+
<field name="Birthday"/>
|
21
|
+
</Group_Tag>
|
22
|
+
<Group_Tag name='Lead Information'>
|
23
|
+
<field name="Contact Owner">Jimbo Watunusi</field>
|
24
|
+
<field name="First Referrer"/>
|
25
|
+
<field name="Last Referrer"/>
|
26
|
+
<field name="Lead Source"/>
|
27
|
+
<field name="Campaign"/>
|
28
|
+
<field name="Ad"/>
|
29
|
+
<field name="Media"/>
|
30
|
+
</Group_Tag>
|
31
|
+
<Group_Tag name='Sequences and Tags'>
|
32
|
+
<field name="Sequences">*/*</field>
|
33
|
+
<field name="Contact Tags"/>
|
34
|
+
</Group_Tag>
|
35
|
+
<Group_Tag name='Purchase History'></Group_Tag>
|
36
|
+
<Group_Tag name='Most Recent Charge'>
|
37
|
+
<field name="Charge Amount">$0.00</field>
|
38
|
+
<field name="Charge Invoice #"/>
|
39
|
+
</Group_Tag>
|
40
|
+
<Group_Tag name='Affiliate Data'>
|
41
|
+
<field name="Affiliate Program"/>
|
42
|
+
<field name="Number of Sales"/>
|
43
|
+
<field name="$ Sales">$0.00</field>
|
44
|
+
<field name="Paypal E-mail"/>
|
45
|
+
<field name="Affiliate Paypal"/>
|
46
|
+
</Group_Tag>
|
47
|
+
<Group_Tag name='Most Recent Invoice'>
|
48
|
+
<field name="Invoice #"/>
|
49
|
+
<field name="Total Invoice Amount">$0.00</field>
|
50
|
+
</Group_Tag>
|
51
|
+
<Group_Tag name='Lead Status'>
|
52
|
+
<field name="Lead Status"/>
|
53
|
+
<field name="Preferencia Contacto"/>
|
54
|
+
</Group_Tag>
|
55
|
+
<Group_Tag name='Credit Card'>
|
56
|
+
<field name="Card Type"/>
|
57
|
+
<field name="Card Expiration Month"/>
|
58
|
+
<field name="Charge Result"/>
|
59
|
+
<field name="Card Expiration Year"/>
|
60
|
+
<field name="Card Number (Last 4)"/>
|
61
|
+
<field name="Payment Center Link"/>
|
62
|
+
</Group_Tag>
|
63
|
+
<Group_Tag name='Invoices'></Group_Tag>
|
64
|
+
<Group_Tag name='Subscriptions and Payment Plans'></Group_Tag>
|
65
|
+
<Group_Tag name='Website Subscribers'></Group_Tag>
|
66
|
+
</contact>
|
67
|
+
<contact id='5' date='1296056609' dlm='1296056694' score='0.00' purl='Paciente2' bulk_mail='1'>
|
68
|
+
<Group_Tag name='Contact Information'>
|
69
|
+
<field name="First Name">Ali</field>
|
70
|
+
<field name="Last Name">Maju</field>
|
71
|
+
<field name="E-Mail">ali@example.com</field>
|
72
|
+
<field name="Home Phone">1234</field>
|
73
|
+
<field name="Title"/>
|
74
|
+
<field name="Office Phone">1234123</field>
|
75
|
+
<field name="Cell Phone">123444</field>
|
76
|
+
<field name="Fax"/>
|
77
|
+
<field name="Address"/>
|
78
|
+
<field name="Company"/>
|
79
|
+
<field name="Address 2"/>
|
80
|
+
<field name="City"/>
|
81
|
+
<field name="State"/>
|
82
|
+
<field name="Zip Code"/>
|
83
|
+
<field name="Website "/>
|
84
|
+
<field name="Country"/>
|
85
|
+
<field name="Birthday"/>
|
86
|
+
</Group_Tag>
|
87
|
+
<Group_Tag name='Lead Information'>
|
88
|
+
<field name="Contact Owner">Jimbo Watunusi</field>
|
89
|
+
<field name="First Referrer"/>
|
90
|
+
<field name="Last Referrer"/>
|
91
|
+
<field name="Lead Source"/>
|
92
|
+
<field name="Campaign"/>
|
93
|
+
<field name="Ad"/>
|
94
|
+
<field name="Media"/>
|
95
|
+
</Group_Tag>
|
96
|
+
<Group_Tag name='Sequences and Tags'>
|
97
|
+
<field name="Sequences">*/*</field>
|
98
|
+
<field name="Contact Tags"/>
|
99
|
+
</Group_Tag>
|
100
|
+
<Group_Tag name='Purchase History'></Group_Tag>
|
101
|
+
<Group_Tag name='Most Recent Charge'>
|
102
|
+
<field name="Charge Amount">$0.00</field>
|
103
|
+
<field name="Charge Invoice #"/>
|
104
|
+
</Group_Tag>
|
105
|
+
<Group_Tag name='Affiliate Data'>
|
106
|
+
<field name="Affiliate Program"/>
|
107
|
+
<field name="Number of Sales"/>
|
108
|
+
<field name="$ Sales">$0.00</field>
|
109
|
+
<field name="Paypal E-mail"/>
|
110
|
+
<field name="Affiliate Paypal"/>
|
111
|
+
</Group_Tag>
|
112
|
+
<Group_Tag
|
113
|
+
name='Most Recent Invoice'>
|
114
|
+
<field name="Invoice #"/>
|
115
|
+
<field name="Total Invoice Amount">$0.00</field>
|
116
|
+
</Group_Tag>
|
117
|
+
<Group_Tag name='Lead Status'>
|
118
|
+
<field name="Lead Status">ASSIGNED</field>
|
119
|
+
<field name="Preferencia Contacto">Entre las 13 y 16</field>
|
120
|
+
</Group_Tag>
|
121
|
+
<Group_Tag name='Credit Card'>
|
122
|
+
<field name="Card Type"/>
|
123
|
+
<field name="Card Expiration Month"/>
|
124
|
+
<field name="Charge Result"/>
|
125
|
+
<field name="Card Expiration Year"/>
|
126
|
+
<field name="Card Number (Last 4)"/>
|
127
|
+
<field name="Payment Center Link"/>
|
128
|
+
</Group_Tag>
|
129
|
+
<Group_Tag name='Invoices'></Group_Tag>
|
130
|
+
<Group_Tag name='Subscriptions and Payment Plans'></Group_Tag>
|
131
|
+
<Group_Tag name='Website Subscribers'></Group_Tag>
|
132
|
+
</contact>
|
133
|
+
<contact id='7' date='1299671887' dlm='1299674450' score='0.00' purl='prashant' bulk_mail='1'>
|
134
|
+
<Group_Tag name='Contact Information'>
|
135
|
+
<field name="First Name">prashant</field>
|
136
|
+
<field name="Last Name">nadarajan</field>
|
137
|
+
<field name="E-Mail">prashant@example.com</field>
|
138
|
+
<field name="Home Phone"/>
|
139
|
+
<field name="Title"/>
|
140
|
+
<field name="Office Phone"/>
|
141
|
+
<field name="Cell Phone"/>
|
142
|
+
<field name="Fax"/>
|
143
|
+
<field name="Address"/>
|
144
|
+
<field name="Company"/>
|
145
|
+
<field name="Address 2"/>
|
146
|
+
<field name="City"/>
|
147
|
+
<field name="State"/>
|
148
|
+
<field name="Zip Code"/>
|
149
|
+
<field name="Website "/>
|
150
|
+
<field name="Country"/>
|
151
|
+
<field name="Birthday"/>
|
152
|
+
</Group_Tag>
|
153
|
+
<Group_Tag name='Lead Information'>
|
154
|
+
<field name="Contact Owner">Don Corleone</field>
|
155
|
+
<field name="First Referrer"/>
|
156
|
+
<field name="Last Referrer"/>
|
157
|
+
<field name="Lead Source"/>
|
158
|
+
<field name="Campaign"/>
|
159
|
+
<field name="Ad"/>
|
160
|
+
<field name="Media"/>
|
161
|
+
</Group_Tag>
|
162
|
+
<Group_Tag name='Sequences and Tags'>
|
163
|
+
<field name="Sequences">*/*</field>
|
164
|
+
<field name="Contact Tags"/>
|
165
|
+
</Group_Tag>
|
166
|
+
<Group_Tag name='Purchase History'></Group_Tag>
|
167
|
+
<Group_Tag name='Most Recent Charge'>
|
168
|
+
<field name="Charge Amount">$0.00</field>
|
169
|
+
<field name="Charge Invoice #"/>
|
170
|
+
</Group_Tag>
|
171
|
+
<Group_Tag name='Affiliate Data'>
|
172
|
+
<field name="Affiliate Program"/>
|
173
|
+
<field name="Number of Sales"/>
|
174
|
+
<field name="$ Sales">$0.00</field>
|
175
|
+
<field name="Paypal E-mail"/>
|
176
|
+
<field name="Affiliate Paypal"/>
|
177
|
+
</Group_Tag>
|
178
|
+
<Group_Tag name='Most Recent Invoice'>
|
179
|
+
<field name="Invoice #"/>
|
180
|
+
<field name="Total Invoice Amount">$0.00</field>
|
181
|
+
</Group_Tag>
|
182
|
+
<Group_Tag name='Lead Status'>
|
183
|
+
<field name="Lead Status"/>
|
184
|
+
<field name="Preferencia Contacto"/>
|
185
|
+
</Group_Tag>
|
186
|
+
<Group_Tag name='Credit Card'>
|
187
|
+
<field name="Card Type"/>
|
188
|
+
<field name="Card Expiration Month"/>
|
189
|
+
<field name="Charge Result"/>
|
190
|
+
<field name="Card Expiration Year"/>
|
191
|
+
<field name="Card Number (Last 4)"/>
|
192
|
+
<field name="Payment Center Link"/>
|
193
|
+
</Group_Tag>
|
194
|
+
<Group_Tag name='Invoices'></Group_Tag>
|
195
|
+
<Group_Tag name='Subscriptions and Payment Plans'></Group_Tag>
|
196
|
+
<Group_Tag name='Website Subscribers'></Group_Tag>
|
197
|
+
</contact>
|
198
|
+
</result>
|
@@ -0,0 +1,68 @@
|
|
1
|
+
<result>
|
2
|
+
<contact id='7' date='1299671887' dlm='1299674450' score='0.00' purl='prashant' bulk_mail='1'>
|
3
|
+
<Group_Tag name='Contact Information'>
|
4
|
+
<field name="First Name">prashant</field>
|
5
|
+
<field name="Last Name">nadarajan</field>
|
6
|
+
<field name="E-Mail">prashant@example.com</field>
|
7
|
+
<field name="Home Phone"/>
|
8
|
+
<field name="Title"/>
|
9
|
+
<field name="Office Phone"/>
|
10
|
+
<field name="Cell Phone"/>
|
11
|
+
<field name="Fax"/>
|
12
|
+
<field name="Address"/>
|
13
|
+
<field name="Company"/>
|
14
|
+
<field name="Address 2"/>
|
15
|
+
<field name="City"/>
|
16
|
+
<field name="State"/>
|
17
|
+
<field name="Zip Code"/>
|
18
|
+
<field name="Website "/>
|
19
|
+
<field name="Country"/>
|
20
|
+
<field name="Birthday"/>
|
21
|
+
</Group_Tag>
|
22
|
+
<Group_Tag name='Lead Information'>
|
23
|
+
<field name="Contact Owner">Don Corleone</field>
|
24
|
+
<field name="First Referrer"/>
|
25
|
+
<field name="Last Referrer"/>
|
26
|
+
<field name="Lead Source"/>
|
27
|
+
<field name="Campaign"/>
|
28
|
+
<field name="Ad"/>
|
29
|
+
<field name="Media"/>
|
30
|
+
</Group_Tag>
|
31
|
+
<Group_Tag name='Sequences and Tags'>
|
32
|
+
<field name="Sequences">*/*</field>
|
33
|
+
<field name="Contact Tags"/>
|
34
|
+
</Group_Tag>
|
35
|
+
<Group_Tag name='Purchase History'></Group_Tag>
|
36
|
+
<Group_Tag name='Most Recent Charge'>
|
37
|
+
<field name="Charge Amount">$0.00</field>
|
38
|
+
<field name="Charge Invoice #"/>
|
39
|
+
</Group_Tag>
|
40
|
+
<Group_Tag name='Affiliate Data'>
|
41
|
+
<field name="Affiliate Program"/>
|
42
|
+
<field name="Number of Sales"/>
|
43
|
+
<field name="$ Sales">$0.00</field>
|
44
|
+
<field name="Paypal E-mail"/>
|
45
|
+
<field name="Affiliate Paypal"/>
|
46
|
+
</Group_Tag>
|
47
|
+
<Group_Tag
|
48
|
+
name='Most Recent Invoice'>
|
49
|
+
<field name="Invoice #"/>
|
50
|
+
<field name="Total Invoice Amount">$0.00</field>
|
51
|
+
</Group_Tag>
|
52
|
+
<Group_Tag name='Lead Status'>
|
53
|
+
<field name="Lead Status"/>
|
54
|
+
<field name="Preferencia Contacto"/>
|
55
|
+
</Group_Tag>
|
56
|
+
<Group_Tag name='Credit Card'>
|
57
|
+
<field name="Card Type"/>
|
58
|
+
<field name="Card Expiration Month"/>
|
59
|
+
<field name="Charge Result"/>
|
60
|
+
<field name="Card Expiration Year"/>
|
61
|
+
<field name="Card Number (Last 4)"/>
|
62
|
+
<field name="Payment Center Link"/>
|
63
|
+
</Group_Tag>
|
64
|
+
<Group_Tag name='Invoices'></Group_Tag>
|
65
|
+
<Group_Tag name='Subscriptions and Payment Plans'></Group_Tag>
|
66
|
+
<Group_Tag name='Website Subscribers'></Group_Tag>
|
67
|
+
</contact>
|
68
|
+
</result>
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OfficeAutopilot::Client::Contacts do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@contact_endpoint = "#{api_endpoint}/cdata.php"
|
7
|
+
@client = OfficeAutopilot::Client.new(:api_id => 'xxx', :api_key => 'xxx')
|
8
|
+
@auth_str = "Appid=#{@client.api_id}&Key=#{@client.api_key}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse_xml_contacts(xml)
|
12
|
+
contacts = []
|
13
|
+
xml = Nokogiri::XML(xml)
|
14
|
+
xml.css('result contact').each do |node|
|
15
|
+
contacts << {
|
16
|
+
:id => node['id'].to_i,
|
17
|
+
:first_name => node.at_css("Group_Tag[name='Contact Information'] field[name='First Name']").text,
|
18
|
+
:last_name => node.at_css("Group_Tag[name='Contact Information'] field[name='Last Name']").text,
|
19
|
+
:email => node.at_css("Group_Tag[name='Contact Information'] field[name='E-Mail']").text
|
20
|
+
}
|
21
|
+
end
|
22
|
+
contacts
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#contacts_search" do
|
26
|
+
context "when the results contain one user" do
|
27
|
+
it "returns an array containing the contact" do
|
28
|
+
search_params = {:field => 'E-Mail', :op => 'e', :value => 'prashant@example.com'}
|
29
|
+
xml_request = @client.xml_for_search(search_params)
|
30
|
+
xml_response = test_data('contacts_search_single_response.xml')
|
31
|
+
|
32
|
+
stub_request(:post, @contact_endpoint).with(
|
33
|
+
:body => "reqType=search&data=#{escape_xml(xml_request)}&#{@auth_str}"
|
34
|
+
).to_return(:body => xml_response)
|
35
|
+
|
36
|
+
xml_contacts = parse_xml_contacts(xml_response)
|
37
|
+
|
38
|
+
response = @client.contacts_search(search_params)
|
39
|
+
response.each_with_index do |contact, index|
|
40
|
+
contact[:id].should == xml_contacts[index][:id]
|
41
|
+
contact[:first_name].should == xml_contacts[index][:first_name]
|
42
|
+
contact[:last_name].should == xml_contacts[index][:last_name]
|
43
|
+
contact[:email].should == xml_contacts[index][:email]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when the results contain more than one user" do
|
49
|
+
it "returns an array containing the contacts" do
|
50
|
+
search_params = {:field => 'E-Mail', :op => 'c', :value => ''}
|
51
|
+
xml_request = @client.xml_for_search(search_params)
|
52
|
+
xml_response = test_data('contacts_search_multiple_response.xml')
|
53
|
+
|
54
|
+
stub_request(:post, @contact_endpoint).with(
|
55
|
+
:body => "reqType=search&data=#{escape_xml(xml_request)}&#{@auth_str}"
|
56
|
+
).to_return(:body => xml_response)
|
57
|
+
|
58
|
+
xml_contacts = parse_xml_contacts(xml_response)
|
59
|
+
|
60
|
+
response = @client.contacts_search(search_params)
|
61
|
+
response.each_with_index do |contact, index|
|
62
|
+
contact[:id].should == xml_contacts[index][:id]
|
63
|
+
contact[:first_name].should == xml_contacts[index][:first_name]
|
64
|
+
contact[:last_name].should == xml_contacts[index][:last_name]
|
65
|
+
contact[:email].should == xml_contacts[index][:email]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OfficeAutopilot::Client do
|
4
|
+
|
5
|
+
describe "#new" do
|
6
|
+
before do
|
7
|
+
@api_id = 'foo'
|
8
|
+
@api_key = 'bar'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "initializes the API credentials" do
|
12
|
+
client = OfficeAutopilot::Client.new(:api_id => @api_id, :api_key => @api_key)
|
13
|
+
client.api_id.should == @api_id
|
14
|
+
client.api_key.should == @api_key
|
15
|
+
client.auth.should == { 'Appid' => @api_id, 'Key' => @api_key }
|
16
|
+
end
|
17
|
+
|
18
|
+
it "raises an ArgumentError when api_id is not provided" do
|
19
|
+
expect {
|
20
|
+
OfficeAutopilot::Client.new(:api_key => 'foo')
|
21
|
+
}.to raise_error(ArgumentError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "raises an ArgumentError when api_key is not provided" do
|
25
|
+
expect {
|
26
|
+
OfficeAutopilot::Client.new(:api_id => 'foo')
|
27
|
+
}.to raise_error(ArgumentError)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "HTTParty" do
|
32
|
+
it "sets the base uri to the Office Autopilot API host" do
|
33
|
+
OfficeAutopilot::Client.base_uri.should == 'http://api.moon-ray.com'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "set the format to :xml" do
|
37
|
+
OfficeAutopilot::Client.format.should == :plain
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#xml_for_search" do
|
42
|
+
before do
|
43
|
+
@client = OfficeAutopilot::Client.new(:api_id => 'xx', :api_key => 'yy')
|
44
|
+
end
|
45
|
+
|
46
|
+
# <search>
|
47
|
+
# <equation>
|
48
|
+
# <field>E-Mail</field>
|
49
|
+
# <op>e</op>
|
50
|
+
# <value>john@example.com</value>
|
51
|
+
# </equation>
|
52
|
+
# </search>
|
53
|
+
|
54
|
+
context "searching with one field" do
|
55
|
+
it "returns a valid simple search data xml" do
|
56
|
+
field = "E-Mail"
|
57
|
+
op = "e"
|
58
|
+
value = "john@example.com"
|
59
|
+
|
60
|
+
xml = Nokogiri::XML(@client.xml_for_search(:field => field, :op => op, :value => value))
|
61
|
+
xml.at_css('field').content.should == field
|
62
|
+
xml.at_css('op').content.should == op
|
63
|
+
xml.at_css('value').content.should == value
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "searching with more than one field" do
|
68
|
+
it "returns a valid multi search data xml" do
|
69
|
+
field = "E-Mail"
|
70
|
+
op = "e"
|
71
|
+
value = "john@example.com"
|
72
|
+
|
73
|
+
search_options = [
|
74
|
+
{:field => 'E-Mail', :op => 'e', :value => 'foo@example.com'},
|
75
|
+
{:field => 'Contact Tags', :op => 'n', :value => 'bar'},
|
76
|
+
]
|
77
|
+
|
78
|
+
xml = @client.xml_for_search(search_options)
|
79
|
+
xml = Nokogiri::XML(xml)
|
80
|
+
xml.css('field')[0].content.should == 'E-Mail'
|
81
|
+
xml.css('op')[0].content.should == 'e'
|
82
|
+
xml.css('value')[0].content.should == 'foo@example.com'
|
83
|
+
xml.css('field')[1].content.should == 'Contact Tags'
|
84
|
+
xml.css('op')[1].content.should == 'n'
|
85
|
+
xml.css('value')[1].content.should == 'bar'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
2
|
+
|
3
|
+
|
4
|
+
require 'office_autopilot'
|
5
|
+
|
6
|
+
require 'cgi'
|
7
|
+
require 'webmock/rspec'
|
8
|
+
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def test_data(file_name)
|
15
|
+
File.read(File.join(File.dirname(__FILE__), 'data', file_name))
|
16
|
+
end
|
17
|
+
|
18
|
+
def api_endpoint
|
19
|
+
'http://api.moon-ray.com'
|
20
|
+
end
|
21
|
+
|
22
|
+
def escape_xml(xml)
|
23
|
+
CGI.escape(xml)
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: office_autopilot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Prashant Nadarajan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-03-12 00:00:00 +08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rake
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0.8"
|
25
|
+
type: :development
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "2.5"
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: webmock
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "1.6"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: httparty
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0.7"
|
58
|
+
type: :runtime
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: builder
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "3.0"
|
69
|
+
type: :runtime
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: nokogiri
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "1.4"
|
80
|
+
type: :runtime
|
81
|
+
version_requirements: *id006
|
82
|
+
description: A Ruby wrapper for the OfficeAutopilot API
|
83
|
+
email:
|
84
|
+
- prashant.nadarajan@gmail.com
|
85
|
+
executables: []
|
86
|
+
|
87
|
+
extensions: []
|
88
|
+
|
89
|
+
extra_rdoc_files: []
|
90
|
+
|
91
|
+
files:
|
92
|
+
- .gitignore
|
93
|
+
- .rspec
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- lib/office_autopilot.rb
|
99
|
+
- lib/office_autopilot/client.rb
|
100
|
+
- lib/office_autopilot/client/contacts.rb
|
101
|
+
- lib/office_autopilot/version.rb
|
102
|
+
- office_autopilot.gemspec
|
103
|
+
- spec/data/contacts_search_multiple_response.xml
|
104
|
+
- spec/data/contacts_search_single_response.xml
|
105
|
+
- spec/office_autopilot/client/contacts_spec.rb
|
106
|
+
- spec/office_autopilot/client_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
has_rdoc: true
|
109
|
+
homepage: https://github.com/prashantrajan/office_autopilot
|
110
|
+
licenses: []
|
111
|
+
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: "0"
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: "0"
|
129
|
+
requirements: []
|
130
|
+
|
131
|
+
rubyforge_project: office_autopilot
|
132
|
+
rubygems_version: 1.6.1
|
133
|
+
signing_key:
|
134
|
+
specification_version: 3
|
135
|
+
summary: Ruby wrapper for the OfficeAutopilot API
|
136
|
+
test_files:
|
137
|
+
- spec/data/contacts_search_multiple_response.xml
|
138
|
+
- spec/data/contacts_search_single_response.xml
|
139
|
+
- spec/office_autopilot/client/contacts_spec.rb
|
140
|
+
- spec/office_autopilot/client_spec.rb
|
141
|
+
- spec/spec_helper.rb
|