Class: Invoiced::Client
- Inherits:
-
Object
- Object
- Invoiced::Client
- Defined in:
- lib/invoiced.rb
Constant Summary collapse
- ApiBase =
'https://api.invoiced.com'
- ApiBaseSandbox =
'https://api.sandbox.invoiced.com'
- OpenTimeout =
30
- ReadTimeout =
80
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_url ⇒ Object
readonly
Returns the value of attribute api_url.
-
#Charge ⇒ Object
readonly
Returns the value of attribute Charge.
-
#Coupon ⇒ Object
readonly
Returns the value of attribute Coupon.
-
#CreditBalanceAdjustment ⇒ Object
readonly
Returns the value of attribute CreditBalanceAdjustment.
-
#CreditNote ⇒ Object
readonly
Returns the value of attribute CreditNote.
-
#Customer ⇒ Object
readonly
Returns the value of attribute Customer.
-
#CustomerChasingCadence ⇒ Object
readonly
Returns the value of attribute CustomerChasingCadence.
-
#CustomField ⇒ Object
readonly
Returns the value of attribute CustomField.
-
#EmailTemplate ⇒ Object
readonly
Returns the value of attribute EmailTemplate.
-
#Estimate ⇒ Object
readonly
Returns the value of attribute Estimate.
-
#Event ⇒ Object
readonly
Returns the value of attribute Event.
-
#File ⇒ Object
readonly
Returns the value of attribute File.
-
#GlAccount ⇒ Object
readonly
Returns the value of attribute GlAccount.
-
#Inbox ⇒ Object
readonly
Returns the value of attribute Inbox.
-
#Invoice ⇒ Object
readonly
Returns the value of attribute Invoice.
-
#InvoiceChasingCadence ⇒ Object
readonly
Returns the value of attribute InvoiceChasingCadence.
-
#Item ⇒ Object
readonly
Returns the value of attribute Item.
-
#LateFeeSchedule ⇒ Object
readonly
Returns the value of attribute LateFeeSchedule.
-
#Member ⇒ Object
readonly
Returns the value of attribute Member.
-
#MerchantAccount ⇒ Object
readonly
Returns the value of attribute MerchantAccount.
-
#Note ⇒ Object
readonly
Returns the value of attribute Note.
-
#Payment ⇒ Object
readonly
Returns the value of attribute Payment.
-
#PaymentMethod ⇒ Object
readonly
Returns the value of attribute PaymentMethod.
-
#PdfTemplate ⇒ Object
readonly
Returns the value of attribute PdfTemplate.
-
#Plan ⇒ Object
readonly
Returns the value of attribute Plan.
-
#Refund ⇒ Object
readonly
Returns the value of attribute Refund.
-
#Report ⇒ Object
readonly
Returns the value of attribute Report.
-
#Role ⇒ Object
readonly
Returns the value of attribute Role.
-
#sandbox ⇒ Object
readonly
Returns the value of attribute sandbox.
-
#SignUpPage ⇒ Object
readonly
Returns the value of attribute SignUpPage.
-
#SmsTemplate ⇒ Object
readonly
Returns the value of attribute SmsTemplate.
-
#sso_key ⇒ Object
readonly
Returns the value of attribute sso_key.
-
#Subscription ⇒ Object
readonly
Returns the value of attribute Subscription.
-
#Task ⇒ Object
readonly
Returns the value of attribute Task.
-
#TaxRate ⇒ Object
readonly
Returns the value of attribute TaxRate.
-
#TaxRule ⇒ Object
readonly
Returns the value of attribute TaxRule.
-
#Theme ⇒ Object
readonly
Returns the value of attribute Theme.
-
#Webhook ⇒ Object
readonly
Returns the value of attribute Webhook.
Instance Method Summary collapse
- #generate_sign_in_token(customerId, ttl) ⇒ Object
-
#initialize(api_key, sandbox = false, sso_key = false) ⇒ Client
constructor
A new instance of Client.
- #request(method, endpoint, params = {}, opts = {}) ⇒ Object
Constructor Details
#initialize(api_key, sandbox = false, sso_key = false) ⇒ Client
Returns a new instance of Client.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/invoiced.rb', line 80 def initialize(api_key, sandbox=false, sso_key=false) @api_key = api_key @sandbox = sandbox @api_url = sandbox ? ApiBaseSandbox : ApiBase @sso_key = sso_key # Object endpoints @Charge = Invoiced::Charge.new(self) @Coupon = Invoiced::Coupon.new(self) @CreditBalanceAdjustment = Invoiced::CreditBalanceAdjustment.new(self) @CreditNote = Invoiced::CreditNote.new(self) @CustomField = Invoiced::CustomField.new(self) @Customer = Invoiced::Customer.new(self) @CustomerChasingCadence = Invoiced::CustomerChasingCadence.new(self) @EmailTemplate = Invoiced::EmailTemplate.new(self) @Estimate = Invoiced::Estimate.new(self) @Event = Invoiced::Event.new(self) @File = Invoiced::File.new(self) @GlAccount = Invoiced::GlAccount.new(self) @Inbox = Invoiced::Inbox.new(self) @Invoice = Invoiced::Invoice.new(self) @InvoiceChasingCadence = Invoiced::InvoiceChasingCadence.new(self) @Item = Invoiced::Item.new(self) @LateFeeSchedule = Invoiced::LateFeeSchedule.new(self) @Member = Invoiced::Member.new(self) @MerchantAccount = Invoiced::MerchantAccount.new(self) @Note = Invoiced::Note.new(self) @Payment = Invoiced::Payment.new(self) @PaymentMethod = Invoiced::PaymentMethod.new(self) @PdfTemplate = Invoiced::PdfTemplate.new(self) @Plan = Invoiced::Plan.new(self) @Refund = Invoiced::Refund.new(self) @Report = Invoiced::Report.new(self) @Role = Invoiced::Role.new(self) @SignUpPage = Invoiced::SignUpPage.new(self) @SmsTemplate = Invoiced::SmsTemplate.new(self) @Subscription = Invoiced::Subscription.new(self) @Task = Invoiced::Task.new(self) @TaxRate = Invoiced::TaxRate.new(self) @TaxRule = Invoiced::TaxRule.new(self) @Theme = Invoiced::Theme.new(self) @Webhook = Invoiced::Webhook.new(self) end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
77 78 79 |
# File 'lib/invoiced.rb', line 77 def api_key @api_key end |
#api_url ⇒ Object (readonly)
Returns the value of attribute api_url.
77 78 79 |
# File 'lib/invoiced.rb', line 77 def api_url @api_url end |
#Charge ⇒ Object (readonly)
Returns the value of attribute Charge.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Charge @Charge end |
#Coupon ⇒ Object (readonly)
Returns the value of attribute Coupon.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Coupon @Coupon end |
#CreditBalanceAdjustment ⇒ Object (readonly)
Returns the value of attribute CreditBalanceAdjustment.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def CreditBalanceAdjustment @CreditBalanceAdjustment end |
#CreditNote ⇒ Object (readonly)
Returns the value of attribute CreditNote.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def CreditNote @CreditNote end |
#Customer ⇒ Object (readonly)
Returns the value of attribute Customer.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Customer @Customer end |
#CustomerChasingCadence ⇒ Object (readonly)
Returns the value of attribute CustomerChasingCadence.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def CustomerChasingCadence @CustomerChasingCadence end |
#CustomField ⇒ Object (readonly)
Returns the value of attribute CustomField.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def CustomField @CustomField end |
#EmailTemplate ⇒ Object (readonly)
Returns the value of attribute EmailTemplate.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def EmailTemplate @EmailTemplate end |
#Estimate ⇒ Object (readonly)
Returns the value of attribute Estimate.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Estimate @Estimate end |
#Event ⇒ Object (readonly)
Returns the value of attribute Event.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Event @Event end |
#File ⇒ Object (readonly)
Returns the value of attribute File.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def File @File end |
#GlAccount ⇒ Object (readonly)
Returns the value of attribute GlAccount.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def GlAccount @GlAccount end |
#Inbox ⇒ Object (readonly)
Returns the value of attribute Inbox.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Inbox @Inbox end |
#Invoice ⇒ Object (readonly)
Returns the value of attribute Invoice.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Invoice @Invoice end |
#InvoiceChasingCadence ⇒ Object (readonly)
Returns the value of attribute InvoiceChasingCadence.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def InvoiceChasingCadence @InvoiceChasingCadence end |
#Item ⇒ Object (readonly)
Returns the value of attribute Item.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Item @Item end |
#LateFeeSchedule ⇒ Object (readonly)
Returns the value of attribute LateFeeSchedule.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def LateFeeSchedule @LateFeeSchedule end |
#Member ⇒ Object (readonly)
Returns the value of attribute Member.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Member @Member end |
#MerchantAccount ⇒ Object (readonly)
Returns the value of attribute MerchantAccount.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def MerchantAccount @MerchantAccount end |
#Note ⇒ Object (readonly)
Returns the value of attribute Note.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Note @Note end |
#Payment ⇒ Object (readonly)
Returns the value of attribute Payment.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Payment @Payment end |
#PaymentMethod ⇒ Object (readonly)
Returns the value of attribute PaymentMethod.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def PaymentMethod @PaymentMethod end |
#PdfTemplate ⇒ Object (readonly)
Returns the value of attribute PdfTemplate.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def PdfTemplate @PdfTemplate end |
#Plan ⇒ Object (readonly)
Returns the value of attribute Plan.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Plan @Plan end |
#Refund ⇒ Object (readonly)
Returns the value of attribute Refund.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Refund @Refund end |
#Report ⇒ Object (readonly)
Returns the value of attribute Report.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Report @Report end |
#Role ⇒ Object (readonly)
Returns the value of attribute Role.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Role @Role end |
#sandbox ⇒ Object (readonly)
Returns the value of attribute sandbox.
77 78 79 |
# File 'lib/invoiced.rb', line 77 def sandbox @sandbox end |
#SignUpPage ⇒ Object (readonly)
Returns the value of attribute SignUpPage.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def SignUpPage @SignUpPage end |
#SmsTemplate ⇒ Object (readonly)
Returns the value of attribute SmsTemplate.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def SmsTemplate @SmsTemplate end |
#sso_key ⇒ Object (readonly)
Returns the value of attribute sso_key.
77 78 79 |
# File 'lib/invoiced.rb', line 77 def sso_key @sso_key end |
#Subscription ⇒ Object (readonly)
Returns the value of attribute Subscription.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Subscription @Subscription end |
#Task ⇒ Object (readonly)
Returns the value of attribute Task.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Task @Task end |
#TaxRate ⇒ Object (readonly)
Returns the value of attribute TaxRate.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def TaxRate @TaxRate end |
#TaxRule ⇒ Object (readonly)
Returns the value of attribute TaxRule.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def TaxRule @TaxRule end |
#Theme ⇒ Object (readonly)
Returns the value of attribute Theme.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Theme @Theme end |
#Webhook ⇒ Object (readonly)
Returns the value of attribute Webhook.
78 79 80 |
# File 'lib/invoiced.rb', line 78 def Webhook @Webhook end |
Instance Method Details
#generate_sign_in_token(customerId, ttl) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/invoiced.rb', line 158 def generate_sign_in_token(customerId, ttl) if !@sso_key raise "Please provide a single sign-on key! You can find this value in Settings > Developers > Single Sign-On of the Invoiced application." end expires = Time.now + ttl # TTL should be in seconds payload = { :sub => customerId, :iss => "Invoiced Ruby/#{Invoiced::VERSION}", :iat => Time.now.to_i, :exp => expires.to_i } JWT.encode payload, @sso_key, 'HS256' end |
#request(method, endpoint, params = {}, opts = {}) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/invoiced.rb', line 124 def request(method, endpoint, params={}, opts={}) url = @api_url + endpoint case method.to_s.downcase.to_sym # These methods don't have a request body when :get, :head, :delete # Make params into GET parameters url += "#{URI.parse(url).query ? '&' : '?'}#{Util.uri_encode(params)}" if params && params.any? payload = nil # Otherwise, encode request body to JSON else payload = params.to_json end begin response = RestClient::Request.execute( :method => method, :url => url, :headers => buildHeaders(opts), :payload => payload, :open_timeout => OpenTimeout, :timeout => ReadTimeout ) rescue RestClient::Exception => e if e.response handle_api_error(e.response) else handle_network_error(e) end end parse(response) end |