office_autopilot 0.0.1 → 0.0.3

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/README.md CHANGED
@@ -11,11 +11,22 @@ Usage Examples
11
11
  require "rubygems"
12
12
  require "office_autopilot"
13
13
 
14
- oap = OfficeAutopilot::Client.new(:api_id => 'xxx', :api_key => 'yyy')
14
+ client = OfficeAutopilot::Client.new(:api_id => 'xxx', :api_key => 'yyy')
15
15
 
16
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' } ]
17
+ puts client.contacts_search(:field => 'E-Mail', :op => 'e', :value => 'prashant@example.com')
18
+ # results truncated for brevity but ALL fields (including custom fields) are returned
19
+ => [{"id"=>"7",
20
+ "Contact Information"=>{"First Name"=>"testing", "Last Name"=>"testing", "E-Mail"=>"prashant@example.com"},
21
+ "Lead Information"=>{"Contact Owner"=>"XXX", "First Referrer"=>"", "Last Referrer"=>""},
22
+ "Sequences and Tags"=>{"Sequences"=>"*/*", "Contact Tags"=>""},
23
+ "Purchase History"=>{}
24
+ }]
25
+
26
+ # Add Contact
27
+ puts client.contacts_add({ 'Contact Information' => {'First Name' => 'Turtle', 'Last Name' => 'Jones', 'E-Mail' => 'mrturtles@example.com'} })
28
+ # results truncated for brevity
29
+ => {"id"=>"24", "Contact Information"=>{"First Name"=>"Turtle", "Last Name"=>"Jones", "E-Mail"=>"mrturtles@example.com"}}
19
30
 
20
31
  Documentation
21
32
  -------------
@@ -25,7 +36,6 @@ Todo
25
36
  ----
26
37
 
27
38
  * support ALL API calls
28
- * allow returning all possible contact details instead of the current subset
29
39
 
30
40
  Submitting a Pull Request
31
41
  -------------------------
@@ -36,7 +46,7 @@ Submitting a Pull Request
36
46
  5. Add specs for your feature or bug fix.
37
47
  6. Run <tt>bundle exec rake spec</tt>. If your changes are not 100% covered, go back to step 5.
38
48
  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.)
49
+ 8. Submit a pull request. Please do not include changes to the gemspec or version file. (If you want to create your own version for some reason, please do so in a separate commit.)
40
50
 
41
51
  Copyright
42
52
  ---------
@@ -1,27 +1,77 @@
1
1
  module OfficeAutopilot
2
2
  class Client
3
-
4
3
  module Contacts
5
4
 
6
5
  CONTACTS_ENDPOINT = '/cdata.php'
7
6
 
8
- def contacts_search(options = {})
7
+ def contacts_search(options)
9
8
  xml = xml_for_search(options)
10
- response = self.class.post(CONTACTS_ENDPOINT, :body => {'reqType' => 'search', 'data' => xml}.merge(auth))
9
+ response = request(:post, CONTACTS_ENDPOINT, :body => {'reqType' => 'search', 'data' => xml}.merge(auth))
10
+ parse_contacts_xml(response)
11
+ end
12
+
13
+ def contacts_add(options)
14
+ xml = xml_for_contact(options)
15
+ response = request(:post, CONTACTS_ENDPOINT, :body => {'reqType' => 'add', 'return_id' => '1', 'data' => xml}.merge(auth))
16
+ parse_contacts_xml(response)[0]
17
+ end
18
+
19
+ def xml_for_search(options)
20
+ if options.is_a?(Hash)
21
+ options = [options]
22
+ end
23
+
24
+ xml = Builder::XmlMarkup.new
25
+ xml.search do
26
+ options.each do |option|
27
+ xml.equation do
28
+ xml.field option[:field]
29
+ xml.op option[:op]
30
+ xml.value option[:value]
31
+ end
32
+ end
33
+ end
34
+ end
11
35
 
36
+ def xml_for_contact(options)
37
+ attrs = {}
38
+
39
+ id = options.delete('id')
40
+ attrs[:id] = id if id
41
+
42
+ xml = Builder::XmlMarkup.new
43
+ xml.contact(attrs) do
44
+ options.each_key do |group_tag|
45
+ xml.Group_Tag(:name => group_tag) do
46
+ options[group_tag].each do |field, value|
47
+ xml.field(value, :name => field)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ def parse_contacts_xml(response)
12
55
  contacts = []
13
56
  xml = Nokogiri::XML(response)
14
57
  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
- }
58
+ contact = {}
59
+ contact['id'] = node['id']
60
+
61
+ node.css('Group_Tag').each do |group_tag|
62
+ group_tag_name = group_tag['name']
63
+ contact[group_tag_name] = {}
64
+
65
+ group_tag.css('field').each do |field|
66
+ field_name = field['name']
67
+ contact[group_tag_name][field_name] = field.content
68
+ end
69
+ end
70
+ contacts << contact
21
71
  end
22
72
  contacts
23
73
  end
24
- end
25
74
 
75
+ end
26
76
  end
27
77
  end
@@ -1,21 +1,14 @@
1
- require 'httparty'
2
1
  require 'builder'
3
2
  require 'nokogiri'
4
3
 
5
-
4
+ require File.expand_path('../error', __FILE__)
5
+ require File.expand_path('../request', __FILE__)
6
6
  require File.expand_path('../client/contacts', __FILE__)
7
7
 
8
-
9
8
  module OfficeAutopilot
10
9
  class Client
11
10
 
12
- include HTTParty
13
-
14
- include OfficeAutopilot::Client::Contacts
15
-
16
- base_uri 'http://api.moon-ray.com'
17
- format :plain
18
-
11
+ include Contacts
19
12
 
20
13
  def initialize(options)
21
14
  @api = {
@@ -39,21 +32,18 @@ module OfficeAutopilot
39
32
  { 'Appid' => api_id, 'Key' => api_key }
40
33
  end
41
34
 
42
- def xml_for_search(options)
43
- if options.is_a?(Hash)
44
- options = [ options ]
45
- end
35
+ def request(method, path, options)
36
+ handle_response( OfficeAutopilot::Request.send(method, path, options) )
37
+ end
46
38
 
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
39
+ def handle_response(response)
40
+ xml = Nokogiri::XML(response)
41
+
42
+ if xml.at_css('result').content =~ /failure/i
43
+ raise OfficeAutopilot::XmlError if xml.at_css('result error').content =~ /Invalid XML/i
56
44
  end
45
+
46
+ response
57
47
  end
58
48
 
59
49
  end
@@ -0,0 +1,7 @@
1
+ module OfficeAutopilot
2
+ # Custom error class for rescuing from all OfficeAutopilot errors
3
+ class Error < StandardError; end
4
+
5
+ # Raised when OfficeAutopilot returns <result>failure<error>Invalid XML</error></result>
6
+ class XmlError < Error; end
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'httparty'
2
+
3
+ module OfficeAutopilot
4
+ class Request
5
+
6
+ include HTTParty
7
+ base_uri 'http://api.moon-ray.com'
8
+ format :plain
9
+
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module OfficeAutopilot
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,69 @@
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
+ <status>Success</status>
69
+ </result>
@@ -0,0 +1,3 @@
1
+ <result>failure
2
+ <error>Invalid XML</error>
3
+ </result>
@@ -8,64 +8,157 @@ describe OfficeAutopilot::Client::Contacts do
8
8
  @auth_str = "Appid=#{@client.api_id}&Key=#{@client.api_key}"
9
9
  end
10
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
- }
11
+ describe "#xml_for_search" do
12
+ # <search>
13
+ # <equation>
14
+ # <field>E-Mail</field>
15
+ # <op>e</op>
16
+ # <value>john@example.com</value>
17
+ # </equation>
18
+ # </search>
19
+
20
+ context "searching with one field" do
21
+ it "returns a valid simple search data xml" do
22
+ field = "E-Mail"
23
+ op = "e"
24
+ value = "john@example.com"
25
+
26
+ xml = Nokogiri::XML(@client.xml_for_search(:field => field, :op => op, :value => value))
27
+ xml.at_css('field').content.should == field
28
+ xml.at_css('op').content.should == op
29
+ xml.at_css('value').content.should == value
30
+ end
31
+ end
32
+
33
+ context "searching with more than one field" do
34
+ it "returns a valid multi search data xml" do
35
+ search_options = [
36
+ {:field => 'E-Mail', :op => 'e', :value => 'foo@example.com'},
37
+ {:field => 'Contact Tags', :op => 'n', :value => 'bar'},
38
+ ]
39
+
40
+ xml = @client.xml_for_search(search_options)
41
+ xml = Nokogiri::XML(xml)
42
+ xml.css('field')[0].content.should == 'E-Mail'
43
+ xml.css('op')[0].content.should == 'e'
44
+ xml.css('value')[0].content.should == 'foo@example.com'
45
+
46
+ xml.css('field')[1].content.should == 'Contact Tags'
47
+ xml.css('op')[1].content.should == 'n'
48
+ xml.css('value')[1].content.should == 'bar'
49
+ end
21
50
  end
22
- contacts
23
51
  end
24
52
 
25
53
  describe "#contacts_search" do
26
- context "when the results contain one user" do
54
+ it "returns the matched contacts" do
55
+ search_options = {:field => 'E-Mail', :op => 'e', :value => 'prashant@example.com'}
56
+ search_xml = @client.xml_for_search(search_options)
57
+ contacts_xml = test_data('contacts_search_single_response.xml')
58
+
59
+ request_body = "reqType=search&data=#{escape_xml(search_xml)}&#{@auth_str}"
60
+ stub_request(:post, @contact_endpoint).with(:body => request_body).to_return(:body => contacts_xml)
61
+
62
+ contacts = @client.contacts_search(search_options)
63
+ WebMock.should have_requested(:post, @contact_endpoint).with(:body => request_body)
64
+ contacts.should == @client.parse_contacts_xml(contacts_xml)
65
+ end
66
+ end
67
+
68
+ describe "#xml_for_contact" do
69
+ before do
70
+ @contact_options = {
71
+ 'Contact Information' => {'First Name' => 'Bob', 'Last Name' => 'Foo', 'E-Mail' => 'b@example.com'},
72
+ 'Lead Information' => {'Contact Owner' => 'Mr Bar'}
73
+ }
74
+ end
75
+
76
+ it "returns a valid contacts xml" do
77
+ xml = @client.xml_for_contact(@contact_options)
78
+ xml = Nokogiri::XML(xml)
79
+
80
+ xml.at_css('contact')['id'].should be_nil
81
+
82
+ contact_info = xml.css("contact Group_Tag[name='Contact Information']")
83
+ contact_info.at_css("field[name='First Name']").content.should == 'Bob'
84
+ contact_info.at_css("field[name='Last Name']").content.should == 'Foo'
85
+
86
+ lead_info = xml.css("contact Group_Tag[name='Lead Information']")
87
+ lead_info.at_css("field[name='Contact Owner']").content.should == 'Mr Bar'
88
+ end
89
+
90
+ context "when 'id' is specified" do
91
+ it "returns a valid contact xml containing the contact id" do
92
+ @contact_options.merge!('id' => '1234')
93
+ xml = Nokogiri::XML( @client.xml_for_contact(@contact_options) )
94
+
95
+ xml.at_css('contact')['id'].should == '1234'
96
+ contact_info = xml.css("contact Group_Tag[name='Contact Information']")
97
+ contact_info.at_css("field[name='First Name']").content.should == 'Bob'
98
+ contact_info.at_css("field[name='Last Name']").content.should == 'Foo'
99
+
100
+ lead_info = xml.css("contact Group_Tag[name='Lead Information']")
101
+ lead_info.at_css("field[name='Contact Owner']").content.should == 'Mr Bar'
102
+ end
103
+ end
104
+ end
105
+
106
+ describe "#parse_contacts_xml" do
107
+ context "when the results contain one contact" do
27
108
  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]
109
+ contacts = @client.parse_contacts_xml( test_data('contacts_search_single_response.xml') )
110
+
111
+ contacts.size.should == 1
112
+
113
+ contacts.each do |contact|
114
+ contact['id'].should == '7'
115
+ contact['Contact Information']['First Name'].should == 'prashant'
116
+ contact['Contact Information']['Last Name'].should == 'nadarajan'
117
+ contact['Contact Information']['E-Mail'].should == 'prashant@example.com'
118
+ contact['Lead Information']['Contact Owner'].should == 'Don Corleone'
44
119
  end
45
120
  end
46
121
  end
47
122
 
48
- context "when the results contain more than one user" do
123
+ context "when the results contain more than one contact" do
49
124
  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
125
+ contacts = @client.parse_contacts_xml(test_data('contacts_search_multiple_response.xml'))
126
+
127
+ contacts.size.should == 3
128
+
129
+ contacts[0]['id'].should == '8'
130
+ contacts[0]['Contact Information']['E-Mail'].should == 'bobby@example.com'
131
+ contacts[0]['Lead Information']['Contact Owner'].should == 'Jimbo Watunusi'
132
+
133
+ contacts[1]['id'].should == '5'
134
+ contacts[1]['Contact Information']['E-Mail'].should == 'ali@example.com'
135
+ contacts[1]['Lead Information']['Contact Owner'].should == 'Jimbo Watunusi'
67
136
  end
68
137
  end
69
138
  end
70
139
 
140
+ describe "#contacts_add" do
141
+ it "returns the newly created contact" do
142
+ contact_options = {
143
+ 'Contact Information' => {'First Name' => 'prashant', 'Last Name' => 'nadarajan', 'E-Mail' => 'prashant@example.com'},
144
+ 'Lead Information' => {'Contact Owner' => 'Don Corleone'}
145
+ }
146
+
147
+ request_contact_xml = @client.xml_for_contact(contact_options)
148
+ response_contact_xml = test_data('contacts_add_response.xml')
149
+
150
+ request_body = "reqType=add&return_id=1&data=#{escape_xml(request_contact_xml)}&#{@auth_str}"
151
+ stub_request(:post, @contact_endpoint).with(:body => request_body).to_return(:body => response_contact_xml)
152
+
153
+ contact = @client.contacts_add(contact_options)
154
+ WebMock.should have_requested(:post, @contact_endpoint).with(:body => request_body)
155
+
156
+ contact['id'].should == '7'
157
+ contact['Contact Information']['First Name'].should == 'prashant'
158
+ contact['Contact Information']['Last Name'].should == 'nadarajan'
159
+ contact['Contact Information']['E-Mail'].should == 'prashant@example.com'
160
+ contact['Lead Information']['Contact Owner'].should == 'Don Corleone'
161
+ end
162
+ end
163
+
71
164
  end
@@ -2,87 +2,51 @@ require 'spec_helper'
2
2
 
3
3
  describe OfficeAutopilot::Client do
4
4
 
5
- describe "#new" do
6
- before do
7
- @api_id = 'foo'
8
- @api_key = 'bar'
9
- end
5
+ before do
6
+ @api_id = 'foo'
7
+ @api_key = 'bar'
8
+ @client = OfficeAutopilot::Client.new(:api_id => @api_id, :api_key => @api_key)
9
+ end
10
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 }
11
+ describe "#new" do
12
+ it "initializes with the given API credentials" do
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
16
  end
17
17
 
18
- it "raises an ArgumentError when api_id is not provided" do
18
+ it "raises an ArgumentError when :api_id is not provided" do
19
19
  expect {
20
20
  OfficeAutopilot::Client.new(:api_key => 'foo')
21
21
  }.to raise_error(ArgumentError)
22
22
  end
23
23
 
24
- it "raises an ArgumentError when api_key is not provided" do
24
+ it "raises an ArgumentError when :api_key is not provided" do
25
25
  expect {
26
26
  OfficeAutopilot::Client.new(:api_id => 'foo')
27
27
  }.to raise_error(ArgumentError)
28
28
  end
29
29
  end
30
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
31
+ describe "#request" do
32
+ it "makes a HTTP request" do
33
+ pending "can't seem to stub out OfficeAutopilot::Request.post"
38
34
  end
39
35
  end
40
36
 
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
37
+ describe "#handle_response" do
38
+ context "when there are no errors" do
39
+ it "returns the response verbatim" do
40
+ response = '<result>Success</result>'
41
+ @client.handle_response(response).should == response
64
42
  end
65
43
  end
66
44
 
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'
45
+ context "invalid XML error" do
46
+ it "raises OfficeAutopilot::XmlError" do
47
+ expect {
48
+ @client.handle_response( test_data('invalid_xml_error_response.xml') )
49
+ }.to raise_error(OfficeAutopilot::XmlError)
86
50
  end
87
51
  end
88
52
  end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe OfficeAutopilot::Request do
4
+
5
+ describe "HTTParty" do
6
+ it "sets the base uri to the Office Autopilot API host" do
7
+ OfficeAutopilot::Request.base_uri.should == 'http://api.moon-ray.com'
8
+ end
9
+
10
+ it "set the format to :plain" do
11
+ OfficeAutopilot::Request.format.should == :plain
12
+ end
13
+ end
14
+
15
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,13 @@
1
- #Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
2
-
3
-
4
1
  require 'office_autopilot'
5
2
 
6
3
  require 'cgi'
7
4
  require 'webmock/rspec'
8
5
 
9
6
 
7
+ # disallow all non-local connections
8
+ #WebMock.disable_net_connect!(:allow_localhost => true)
9
+
10
+
10
11
  RSpec.configure do |config|
11
12
  end
12
13
 
@@ -16,9 +17,9 @@ def test_data(file_name)
16
17
  end
17
18
 
18
19
  def api_endpoint
19
- 'http://api.moon-ray.com'
20
+ "http://api.moon-ray.com"
20
21
  end
21
22
 
22
23
  def escape_xml(xml)
23
- CGI.escape(xml)
24
+ CGI.escape(xml).gsub('+', '%20')
24
25
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: office_autopilot
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Prashant Nadarajan
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-12 00:00:00 +08:00
13
+ date: 2011-05-03 00:00:00 +08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -98,12 +98,17 @@ files:
98
98
  - lib/office_autopilot.rb
99
99
  - lib/office_autopilot/client.rb
100
100
  - lib/office_autopilot/client/contacts.rb
101
+ - lib/office_autopilot/error.rb
102
+ - lib/office_autopilot/request.rb
101
103
  - lib/office_autopilot/version.rb
102
104
  - office_autopilot.gemspec
105
+ - spec/data/contacts_add_response.xml
103
106
  - spec/data/contacts_search_multiple_response.xml
104
107
  - spec/data/contacts_search_single_response.xml
108
+ - spec/data/invalid_xml_error_response.xml
105
109
  - spec/office_autopilot/client/contacts_spec.rb
106
110
  - spec/office_autopilot/client_spec.rb
111
+ - spec/office_autopilot/request_spec.rb
107
112
  - spec/spec_helper.rb
108
113
  has_rdoc: true
109
114
  homepage: https://github.com/prashantrajan/office_autopilot
@@ -134,8 +139,11 @@ signing_key:
134
139
  specification_version: 3
135
140
  summary: Ruby wrapper for the OfficeAutopilot API
136
141
  test_files:
142
+ - spec/data/contacts_add_response.xml
137
143
  - spec/data/contacts_search_multiple_response.xml
138
144
  - spec/data/contacts_search_single_response.xml
145
+ - spec/data/invalid_xml_error_response.xml
139
146
  - spec/office_autopilot/client/contacts_spec.rb
140
147
  - spec/office_autopilot/client_spec.rb
148
+ - spec/office_autopilot/request_spec.rb
141
149
  - spec/spec_helper.rb