infusion-api 1.0.1 → 1.0.2

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.
@@ -0,0 +1,141 @@
1
+ module Infusionsoft
2
+ class Client
3
+ # The Email service allows you to email your contacts as well as attaching emails sent
4
+ # elsewhere (this lets you send email from multiple services and still see all communications
5
+ # inside of Infusionsoft).
6
+ module Email
7
+
8
+ # Create a new email template that can be used for future emails
9
+ #
10
+ # @param [String] title
11
+ # @param [String] categories a comma separated list of the categories
12
+ # you want this template in Infusionsoft
13
+ # @param [String] from the from address format use is 'FirstName LastName <email@domain.com>'
14
+ # @param [String] to the email address this template is sent to
15
+ # @param [String] cc a comma separated list of cc email addresses
16
+ # @param [String] bcc a comma separated list of bcc email addresses
17
+ # @param [String] subject
18
+ # @param [String] text_body
19
+ # @param [String] html_body
20
+ # @param [String] content_type can be Text, HTML, Multipart
21
+ # @param [String] merge_context can be Contact, ServiceCall, Opportunity, CreditCard
22
+ def email_add(title, categories, from, to, cc, bcc, subject, text_body, html_body,
23
+ content_type, merge_context)
24
+ response = get('APIEmailService.addEmailTemplate', title, categories, from, to,
25
+ cc, bcc, subject, text_body, html_body, content_type, merge_context)
26
+ end
27
+
28
+ # This will create an item in the email history for a contact. This does not actually
29
+ # send the email, it only places an item into the email history. Using the API to
30
+ # instruct Infusionsoft to send an email will handle this automatically.
31
+ #
32
+ # @param [Integer] contact_id
33
+ # @param [String] from_name the name portion of the from address, not the email
34
+ # @param [String] from_address
35
+ # @param [String] to_address
36
+ # @param [String] cc_addresses
37
+ # @param [String] bcc_addresses
38
+ # @param [String] content_type can be Text, HTML, Multipart
39
+ # @param [String] subject
40
+ # @param [String] html_body
41
+ # @param [String] text_body
42
+ # @param [String] header the header info for this email (will be listed in history)
43
+ # @param [Date] receive_date
44
+ # @param [Date] sent_date
45
+ def email_attach(contact_id, from_name, from_address, to_address, cc_addresses,
46
+ bcc_addresses, content_type, subject, html_body, txt_body,
47
+ header, receive_date, send_date)
48
+ response = get('APIEmailService.attachEmail', contact_id, from_name, from_address,
49
+ to_address, cc_addresses, bcc_addresses, content_type, subject,
50
+ html_body, txt_body, header, receive_date, send_date)
51
+ end
52
+
53
+ # This retrieves all possible merge fields for the context provided.
54
+ #
55
+ # @param [String] merge_context could include Contact, ServiceCall, Opportunity, or CreditCard
56
+ # @return [Array] returns the merge fields for the given context
57
+ def email_get_available_merge_fields(merge_context)
58
+ response = get('APIEmailService.getAvailableMergeFields', merge_context)
59
+ end
60
+
61
+ # Retrieves the details for a particular email template.
62
+ #
63
+ # @param [Integer] id
64
+ # @return [Hash] all data for the email template
65
+ def email_get_template(id)
66
+ response = get('APIEmailService.getEmailTemplate', id)
67
+ end
68
+
69
+ # Retrieves the status of the given email address.
70
+ #
71
+ # @param [String] email_address
72
+ # @return [Integer] 0 = opted out, 1 = single opt-in, 2 = double opt-in
73
+ def email_get_opt_status(email_address)
74
+ response = get('APIEmailService.getOptStatus', email_address)
75
+ end
76
+
77
+ # This method opts-in an email address. This method only works the first time
78
+ # an email address opts-in.
79
+ #
80
+ # @param [String] email_address
81
+ # @param [String] reason
82
+ # This is how you can note why/how this email was opted-in. If a blank
83
+ # reason is passed the system will default a reason of "API Opt In"
84
+ # @return [Boolean]
85
+ def email_optin(email_address, reason)
86
+ response = get('APIEmailService.optIn', email_address, reason)
87
+ end
88
+
89
+ # Opts-out an email address. Note that once an address is opt-out,
90
+ # the API cannot opt it back in.
91
+ #
92
+ # @param [String] email_address
93
+ # @param [String] reason
94
+ # @return [Boolean]
95
+ def email_optout(email_address, reason)
96
+ response = get('APIEmailService.optOut', email_address, reason)
97
+ end
98
+
99
+ # This will send an email to a list of contacts, as well as record the email
100
+ # in the contacts' email history.
101
+ #
102
+ # @param [Array<Integer>] contact_list list of contact ids you want to send this email to
103
+ # @param [String] from_address
104
+ # @param [String] to_address
105
+ # @param [String] cc_address
106
+ # @param [String] bcc_address
107
+ # @param [String] content_type this must be one of the following Text, HTML, or Multipart
108
+ # @param [String] subject
109
+ # @param [String] html_body
110
+ # @param [String] text_body
111
+ # @return [Boolean] returns true/false if the email has been sent
112
+ def email_send(contact_list, from_address, to_address, cc_addresses,
113
+ bcc_addresses, content_type, subject, html_body, text_body)
114
+ response = get('APIEmailService.sendEmail', contact_list, from_address,
115
+ to_address, cc_addresses, bcc_addresses, content_type, subject,
116
+ html_body, text_body)
117
+ end
118
+
119
+ # This method is used to update an already existing email template.
120
+ #
121
+ # @param [Integer] id
122
+ # @param [String] title
123
+ # @param [String] category
124
+ # @param [String] from
125
+ # @param [String] to
126
+ # @param [String] cc
127
+ # @param [String] bcc
128
+ # @param [String subject
129
+ # @param [String] text_body
130
+ # @param [String] html_body
131
+ # @param [String] content_type can be Text, HTML, Multipart
132
+ # @param [String] merge_context can be Contact, ServiceCall, Opportunity, CreditCard
133
+ # @return [Boolean] returns true/false if teamplate was updated successfully
134
+ def email_update_template(id, title, category, from, to, cc, bcc, subject,
135
+ text_body, html_body, content_type, merge_context)
136
+ response = get('APIEmailService.updateEmailTemplate', title, category, from,
137
+ to, cc, bcc, subject, text_body, html_body, content_type, merge_context)
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,26 @@
1
+ module Infusionsoft
2
+ class Client
3
+ module File
4
+ def file_upload(contact_id, file_name, encoded_file_base64)
5
+ response = get('FileService.uploadFile', contact_id, file_name, encoded_file_base64)
6
+ end
7
+
8
+ # returns the Base64 encoded file contents
9
+ def file_get(id)
10
+ response = get('FileService.getFile', id)
11
+ end
12
+
13
+ def file_url(id)
14
+ response = get('FileService.getDownloadUrl', id)
15
+ end
16
+
17
+ def file_rename(id, new_name)
18
+ response = get('FileService.renameFile', id, new_name)
19
+ end
20
+
21
+ def file_replace(id, encoded_file_base64)
22
+ response = get('FileService.replaceFile', id, encoded_file_base64)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,254 @@
1
+ module Infusionsoft
2
+ class Client
3
+ # The Invoice service allows you to manage eCommerce transactions.
4
+ module Invoice
5
+ # Creates a blank order with no items.
6
+ #
7
+ # @param [Integer] contact_id
8
+ # @param [String] description the name this order will display
9
+ # @param [Date] order_date
10
+ # @param [Integer] lead_affiliate_id 0 should be used if none
11
+ # @param [Integer] sale_affiliate_id 0 should be used if none
12
+ # @return [Integer] returns the invoice id
13
+ def invoice_create_blank_order(contact_id, description, order_date, lead_affiliate_id,
14
+ sale_affiliate_id)
15
+ response = get('InvoiceService.createBlankOrder', contact_id, description, order_date,
16
+ lead_affiliate_id, sale_affiliate_id)
17
+ end
18
+
19
+ # Adds a line item to an order. This used to add a Product to an order as well as
20
+ # any other sort of charge/discount.
21
+ #
22
+ # @param [Integer] invoice_id
23
+ # @param [Integer] product_id
24
+ # @param [Integer] type UNKNOWN = 0, SHIPPING = 1, TAX = 2, SERVICE = 3, PRODUCT = 4,
25
+ # UPSELL = 5, FINANCECHARGE = 6, SPECIAL = 7
26
+ # @param [Float] price
27
+ # @param [Integer] quantity
28
+ # @param [String] description a full description of the line item
29
+ # @param [String] notes
30
+ # @return [Boolean] returns true/false if it was added successfully or not
31
+ def invoice_add_order_item(invoice_id, product_id, type, price, quantity, description, notes)
32
+ response = get('InvoiceService.addOrderItem', invoice_id, product_id, type, price,
33
+ quantity, description, notes)
34
+ end
35
+
36
+ # This will cause a credit card to be charged for the amount currently due on an invoice.
37
+ #
38
+ # @param [Integer] invoice_id
39
+ # @param [String] notes a note about the payment
40
+ # @param [Integer] credit_card_id
41
+ # @param [Integer] merchant_account_id
42
+ # @param [Boolean] bypass_commission
43
+ # @return [Hash] containing the following keys {'Successful => [Boolean],
44
+ # 'Code' => [String], 'RefNum' => [String], 'Message' => [String]}
45
+ def invoice_charge_invoice(invoice_id, notes, credit_card_id, merchant_account_id,
46
+ bypass_commissions)
47
+ response = get('InvoiceService.chargeInvoice', invoice_id, notes, credit_card_id,
48
+ merchant_account_id, bypass_commissions)
49
+ end
50
+
51
+ # Deletes the specified subscription from the database, as well as all invoices
52
+ # tied to the subscription.
53
+ #
54
+ # @param [Integer] cprogram_id the id of the subscription being deleted
55
+ # @return [Boolean]
56
+ def invoice_delete_subscription(cprogram_id)
57
+ response = get('InvoiceService.deleteSubscription', cprogram_id)
58
+ end
59
+
60
+ # Creates a subscription for a contact. Subscriptions are billing automatically
61
+ # by infusionsoft within the next six hours. If you want to bill immediately you
62
+ # will need to utilize the create_invoice_for_recurring and then
63
+ # charge_invoice method to accomplish this.
64
+ #
65
+ # @param [Integer] contact_id
66
+ # @param [Boolean] allow_duplicate
67
+ # @param [Integer] cprogram_id the subscription id
68
+ # @param [Integer] merchant_account_id
69
+ # @param [Integer] credit_card_id
70
+ # @param [Integer] affiliate_id
71
+ # @param [Integer] days_till_charge number of days you want to wait till it's charged
72
+ def invoice_add_recurring_order(contact_id, allow_duplicate, cprogram_id,
73
+ merchant_account_id, credit_card_id, affiliate_id,
74
+ days_till_charge)
75
+ response = get('InvoiceService.addRecurringOrder', contact_id,
76
+ allow_duplicate, cprogram_id, merchant_account_id, credit_card_id,
77
+ affiliate_id, days_till_charge)
78
+ end
79
+
80
+ # This modifies the commissions being earned on a particular subscription.
81
+ # This does not affect previously generated invoices for this subscription.
82
+ #
83
+ # @param [Integer] recurring_order_id
84
+ # @param [Integer] affiliate_id
85
+ # @param [Float] amount
86
+ # @param [Integer] paryout_type how commissions will be earned (possible options are
87
+ # 4 - up front earning, 5 - upon customer payment) typically this is 5
88
+ # @return [Boolean]
89
+ def invoice_add_recurring_commission_override(recurring_order_id, affiliate_id,
90
+ amount, payout_type, description)
91
+ response = get('InvoiceService.addRecurringCommissionOverride', recurring_order_id,
92
+ affiliate_id, amount, payout_type, description)
93
+ end
94
+
95
+ # Adds a payment to an invoice without actually processing a charge through a merchant.
96
+ #
97
+ # @param [Integer] invoice_id
98
+ # @param [Float] amount
99
+ # @param [Date] date
100
+ # @param [String] type Cash, Check, Credit Card, Money Order, PayPal, etc.
101
+ # @param [String] description an area useful for noting payment details such as check number
102
+ # @param [Boolean] bypass_commissions
103
+ # @return [Boolean]
104
+ def invoice_add_manual_payment(invoice_id, amount, date, type, description, bypass_commissions)
105
+ response = get('InvoiceService.addManualPayment', invoice_id, amount, date, type,
106
+ description, bypass_commissions)
107
+ end
108
+
109
+ # This will create an invoice for all charges due on a Subscription. If the
110
+ # subscription has three billing cycles that are due, it will create one
111
+ # invoice with all three items attached.
112
+ #
113
+ # @param [Integer] recurring_order_id
114
+ # @return [Integer] returns the id of the invoice that was created
115
+ def invoice_create_invoice_for_recurring(recurring_order_id)
116
+ response = get('InvoiceService.createInvoiceForRecurring', recurring_order_id)
117
+ end
118
+
119
+ # Adds a payment plan to an existing invoice.
120
+ #
121
+ # @param [Integer] invoice_id
122
+ # @param [Boolean]
123
+ # @param [Integer] credit_card_id
124
+ # @param [Integer] merchant_account_id
125
+ # @param [Integer] days_between_retry the number of days Infusionsoft should wait
126
+ # before re-attempting to charge a failed payment
127
+ # @param [Integer] max_retry the maximum number of charge attempts
128
+ # @param [Float] initial_payment_ammount the amount of the very first charge
129
+ # @param [Date] initial_payment_date
130
+ # @param [Date] plan_start_date
131
+ # @param [Integer] number_of_payments the number of payments in this payplan (does not include
132
+ # initial payment)
133
+ # @param [Integer] days_between_payments the number of days between each payment
134
+ # @return [Boolean]
135
+ def invoice_add_payment_plan(invoice_id, auto_charge, credit_card_id,
136
+ merchant_account_id, days_between_retry, max_retry,
137
+ initial_payment_amount, initial_payment_date, plan_start_date,
138
+ number_of_payments, days_between_payments)
139
+ response = get('InvoiceService.addPaymentPlan', invoice_id, auto_charge,
140
+ credit_card_id, merchant_account_id, days_between_retry, max_retry,
141
+ initial_payment_amount, initial_payment_date, plan_start_date, number_of_payments,
142
+ days_between_payments)
143
+ end
144
+
145
+ # Calculates the amount owed for a given invoice.
146
+ #
147
+ # @param [Integer] invoice_id
148
+ # @return [Float]
149
+ def invoice_calculate_amount_owed(invoice_id)
150
+ response = get('InvoiceService.calculateAmountOwed', invoice_id)
151
+ end
152
+
153
+ # Retrieve all Payment Types currently setup under the Order Settings section of Infusionsoft.
154
+ #
155
+ # @return [Array]
156
+ def invoice_get_all_payment_otpions
157
+ response = get('InvoiceService.getAllPaymentOptions')
158
+ end
159
+
160
+ # Retrieves all payments for a given invoice.
161
+ #
162
+ # @param [Integer] invoice_id
163
+ # @return [Array<Hash>] returns an array of payments
164
+ def invoice_get_payments(invoice_id)
165
+ response = get('Invoice.getPayments', invoice_id)
166
+ end
167
+
168
+ # Locates an existing card in the system for a contact, using the last 4 digits.
169
+ #
170
+ # @param [Integer] contact_id
171
+ # @param [Integer] last_four
172
+ # @return [Integer] returns the id of the credit card
173
+ def invoice_locate_existing_card(contact_id, last_four)
174
+ response = get('InvoiceService.locateExistingCard', contact_id, last_four)
175
+ end
176
+
177
+ # Calculates tax, and places it onto the given invoice.
178
+ #
179
+ # @param [Integer] invoice_id
180
+ # @return [Boolean]
181
+ def invoice_recalculate_tax(invoice_id)
182
+ response = get('InvoiceService.recalculateTax', invoice_id)
183
+ end
184
+
185
+ # This will validate a credit card in the system.
186
+ #
187
+ # @param [Integer] credit_card_id if the card is already in the system
188
+ # @return [Hash] returns a hash { 'Valid' => false, 'Message' => 'Card is expired' }
189
+ def invoice_validate_card(credit_card_id)
190
+ response = get('InvoiceService.validateCreditCard', credit_card_id)
191
+ end
192
+
193
+ # This will validate a credit card by passing in values of the
194
+ # card directly (this card doesn't have to be added to the system).
195
+ #
196
+ # @param [Hash] data
197
+ # @return [Hash] returns a hash { 'Valid' => false, 'Message' => 'Card is expired' }
198
+ def invoice_validate_card(data)
199
+ response = get('InvoiceService.validateCreditCard', data)
200
+ end
201
+
202
+ # Retrieves the shipping options currently setup for the Infusionsoft shopping cart.
203
+ #
204
+ # @return [Array]
205
+ def invoice_get_all_shipping_options
206
+ response = get('Invoice.getAllShippingOptions')
207
+ end
208
+
209
+ # Changes the next bill date on a subscription.
210
+ #
211
+ # @param [Integer] job_recurring_id this is the subscription id on the contact
212
+ # @param [Date] next_bill_date
213
+ # @return [Boolean]
214
+ def invoice_update_recurring_next_bill_date(job_recurring_id, next_bill_date)
215
+ response = get('InvoiceService.updateJobRecurringNextBillDate', job_recurring_id, next_bill_date)
216
+ end
217
+
218
+
219
+ # Adds a commission override to a one time order, using a combination of percentage
220
+ # and hard-coded amounts.
221
+ #
222
+ # @param [Integer] invoice_id
223
+ # @param [Integer] affiliate_id
224
+ # @param [Integer] product_id
225
+ # @param [Integer] percentage
226
+ # @param [Float] amount
227
+ # @param [Integer] payout_type how commision should be earned (4 - up front in full, 5 - upon
228
+ # customer payment
229
+ # @param [String] description a note about this commission
230
+ # @param [Date] date the commission was generated, not necessarily earned
231
+ # @return [Boolean]
232
+ def invoice_add_order_commission_override(invoice_id, affiliate_id, product_id, percentage,
233
+ amount, payout_type, description, date)
234
+ response = get('InvoiceService.addOrderCommissionOverride', invoice_id, affiliate_id,
235
+ product_id, percentage, amount, payout_type, description, date)
236
+ end
237
+
238
+
239
+ # Deprecated - Adds a recurring order to the database.
240
+ def invoice_add_recurring_order_with_price(contact_id, allow_duplicate, cprogram_id, qty,
241
+ price, allow_tax, merchant_account_id,
242
+ credit_card_id, affiliate_id, days_till_charge)
243
+ response = get('InvoiceService.addRecurringOrder', contact_id, allow_duplicate,
244
+ cprogram_id, qty, price, allow_tax, merchant_account_id, credit_card_id,
245
+ affiliate_id, days_till_charge)
246
+ end
247
+
248
+ # Deprecated - returns the invoice id from a one time order.
249
+ def invoice_get_invoice_id(order_id)
250
+ response = get('InvoiceService.getinvoice_id', order_id)
251
+ end
252
+ end
253
+ end
254
+ end
@@ -0,0 +1,66 @@
1
+ module Infusionsoft
2
+ class Client
3
+ # The SearchService allows you to retrieve the results of saved searches and reports that
4
+ # have been saved within Infusionsoft. Saved searches/reports are tied to the User that
5
+ # created them. This service also allows you to utilize the quick search function found in
6
+ # the upper right hand corner of your Infusionsoft application.
7
+
8
+ # @note In order to retrieve the id number for saved searches you will need to utilize
9
+ # the data_query method and query the table called SavedFilter based on the user_id
10
+ # you are looking for the saved search Id for. Also note that UserId field on the
11
+ # SavedFilter table can contain multiple userId’s separated by a comma, so if you are
12
+ # querying for a report created by userId 6, I recommend appending the wildcard to the
13
+ # end of the userId. Something like $query = array( ‘UserId’ => ’6%’ );
14
+ module Search
15
+ # Gets all possible fields/columns available for return on a saved search/report.
16
+ #
17
+ # @param [Integer] saved_search_id
18
+ # @param [Integer] user_id the user id who the saved search is assigned to
19
+ # @return [Hash]
20
+ def search_get_all_report_columns(saved_search_id, user_id)
21
+ response = get('SearchService.getAllReportColumns', saved_search_id, user_id)
22
+ end
23
+
24
+ # Runs a saved search/report and returns all possible fields.
25
+ #
26
+ # @param [Integer] saved_search_id
27
+ # @param [Integer] user_id the user id who the saved search is assigned to
28
+ # @param [Integer] page_number
29
+ # @return [Hash]
30
+ def search_get_saved_search_results(saved_search_id, user_id, page_number)
31
+ response = get('SearchService.getSavedSearchResultsAllFields', saved_search_id,
32
+ user_id, page_number)
33
+ end
34
+
35
+ # This is used to find what possible quick searches the given user has access to.
36
+ #
37
+ # @param [Integer] user_id
38
+ # @return [Array]
39
+ def search_get_available_quick_searches(user_id)
40
+ response = get('SearchService.getAvailableQuickSearches', user_id)
41
+ end
42
+
43
+ # This allows you to run a quick search via the API. The quick search is the
44
+ # search bar in the upper right hand corner of the Infusionsoft application
45
+ #
46
+ # @param [String] search_type the type of search (Person, Order, Opportunity, Company, Task,
47
+ # Subscription, or Affiliate)
48
+ # @param [Integer] user_id
49
+ # @param [String] search_data
50
+ # @param [Integer] page
51
+ # @param [Integer] limit max is 1000
52
+ # @return [Array<Hash>]
53
+ def search_quick_search(search_type, user_id, search_data, page, limit)
54
+ response = get('SearchService.quickSearch', search_type, user_id, search_data, page, limit)
55
+ end
56
+
57
+ # Retrieves the quick search type that the given users has set as their default.
58
+ #
59
+ # @param [Integer] user_id
60
+ # @return [String] the quick search type that the given user selected as their default
61
+ def search_get_default_search_type(user_id)
62
+ response = get('SearchService.getDefaultQuickSearch', user_id)
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,18 @@
1
+ module Infusionsoft
2
+ class Client
3
+ module Ticket
4
+ # add move notes to existing tickets
5
+ def ticket_add_move_notes(ticket_list, move_notes,
6
+ move_to_stage_id, notify_ids)
7
+ response = get('ServiceCallService.addMoveNotes', ticket_list,
8
+ move_notes, move_to_stage_id, notify_ids)
9
+ end
10
+
11
+ # add move notes to existing tickets
12
+ def ticket_move_stage(ticket_id, ticket_stage, move_notes, notify_ids)
13
+ response = get('ServiceCallService.moveTicketStage',
14
+ ticket_id, ticket_stage, move_notes, notify_ids)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ module Infusionsoft
2
+ # The version of the gem
3
+ VERSION = '1.0.2'.freeze unless defined?(::Infusionsoft::VERSION)
4
+ end
@@ -0,0 +1,29 @@
1
+ module Infusionsoft
2
+ # Wrapper for the Infusionsoft API
3
+ #
4
+ # @note all services have been separated into different modules
5
+ class Client < Api
6
+ # Require client method modules after initializing the Client class in
7
+ # order to avoid a superclass mismatch error, allowing those modules to be
8
+ # Client-namespaced.
9
+ require 'infusionsoft/client/contact'
10
+ require 'infusionsoft/client/email'
11
+ require 'infusionsoft/client/invoice'
12
+ require 'infusionsoft/client/data'
13
+ require 'infusionsoft/client/affiliate'
14
+ require 'infusionsoft/client/file'
15
+ require 'infusionsoft/client/ticket' # Deprecated by Infusionsoft
16
+ require 'infusionsoft/client/search'
17
+ require 'infusionsoft/client/credit_card'
18
+
19
+ include Infusionsoft::Client::Contact
20
+ include Infusionsoft::Client::Email
21
+ include Infusionsoft::Client::Invoice
22
+ include Infusionsoft::Client::Data
23
+ include Infusionsoft::Client::Affiliate
24
+ include Infusionsoft::Client::File
25
+ include Infusionsoft::Client::Ticket # Deprecated by Infusionsoft
26
+ include Infusionsoft::Client::Search
27
+ include Infusionsoft::Client::CreditCard
28
+ end
29
+ end
@@ -0,0 +1,36 @@
1
+ module Infusionsoft
2
+
3
+ module Configuration
4
+ VALID_OPTION_KEYS = [
5
+ :api_url,
6
+ :api_key
7
+ ].freeze
8
+
9
+ # @private
10
+ attr_accessor *VALID_OPTION_KEYS
11
+
12
+ # When this module is extended, set all configuration options to their default values
13
+ #def self.extended(base)
14
+ #base.reset
15
+ #end
16
+
17
+ # Convenience method to allow configuration options to be set in a block
18
+ def configure
19
+ yield self
20
+ end
21
+
22
+ # Create a hash of options and their values
23
+ def options
24
+ options = {}
25
+ VALID_OPTION_KEYS.each{|k| options[k] = send(k)}
26
+ options
27
+ end
28
+
29
+ #def reset
30
+ #self.url = ''
31
+ #self.api_key = 'na'
32
+ #end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,49 @@
1
+ require "xmlrpc/client"
2
+
3
+ module Infusionsoft
4
+ module Connection
5
+ private
6
+
7
+ def connection(service_call, *args)
8
+ server = XMLRPC::Client.new3({
9
+ 'host' => api_url,
10
+ 'path' => "/api/xmlrpc",
11
+ 'port' => 443,
12
+ 'use_ssl' => true
13
+ })
14
+ begin
15
+ result = server.call("#{service_call}", api_key, *args)
16
+ if result.nil?; result = [] end
17
+ rescue Timeout::Error => timeout
18
+ # Retry up to 5 times on a Timeout before raising it
19
+ ok_to_retry(timeout) ? retry : raise
20
+ rescue => e
21
+ # Wrap the underlying error in an InfusionAPIError
22
+ raise InfusionAPIError.new(e.to_s, e)
23
+ end
24
+
25
+ return result
26
+ end
27
+
28
+ def ok_to_retry(e)
29
+ @retry_count += 1
30
+ if @retry_count <= 5
31
+ Rails.logger.info "!!! INFUSION API ERROR: [#{e}] retrying #{@retry_count}" if Rails
32
+ true
33
+ else
34
+ false
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+
41
+ # Extend StandardError to keep track of Error being wrapped
42
+ # Pattern from Exceptional Ruby by Avdi Grimm (http://avdi.org/talks/exceptional-ruby-2011-02-04/)
43
+ class InfusionAPIError < StandardError
44
+ attr_reader :original
45
+ def initialize(msg, original=nil);
46
+ super(msg);
47
+ @original = original;
48
+ end
49
+ end
@@ -0,0 +1,34 @@
1
+ module Infusionsoft
2
+ module Request
3
+ # Perform an GET request
4
+ def get(service_call, *args)
5
+ request(:get, service_call, *args)
6
+ end
7
+
8
+ def post(path, params={}, options={})
9
+ request(:post, path, params, options)
10
+ end
11
+
12
+ # Perform an HTTP PUT request
13
+ def put(path, params={}, options={})
14
+ request(:put, path, params, options)
15
+ end
16
+
17
+ # Perform an HTTP DELETE request
18
+ def delete(path, params={}, options={})
19
+ request(:delete, path, params, options)
20
+ end
21
+
22
+
23
+ private
24
+
25
+ # Perform request
26
+ def request(method, service_call, *args)
27
+ Rails.logger "<<<< Performing API Request to #{api_url}"
28
+ case method.to_sym
29
+ when :get
30
+ response = connection(service_call, *args)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,4 @@
1
+ module Infusionsoft
2
+ # The version of the gem
3
+ VERSION = '1.0.2'.freeze unless defined?(::Infusionsoft::VERSION)
4
+ end