Class: Xero::Api

Inherits:
Object
  • Object
show all
Extended by:
Configuration
Includes:
Attachment, Connection, Methods, Util
Defined in:
lib/xero/api.rb,
lib/xero/api/util.rb,
lib/xero/api/error.rb,
lib/xero/api/methods.rb,
lib/xero/api/version.rb,
lib/xero/api/attachment.rb,
lib/xero/api/connection.rb,
lib/xero/api/configuration.rb,
lib/xero/api/connection/oauth1.rb,
lib/xero/api/connection/oauth2.rb

Defined Under Namespace

Modules: Attachment, Configuration, Connection, FaradayMiddleware, Methods, Util Classes: BadRequest, Error, InternalError, NotFound, NotImplemented, PreconditionFailed, ServiceUnavailable, Unauthorized

Constant Summary collapse

V2_ENDPOINT_BASE_URL =
'https://api.xero.com/api.xro/2.0/'
LOG_TAG =
"[xero-api gem]"
VERSION =
"1.0.1"
OAUTH1_BASE =
'https://api.xero.com/oauth'
OAUTH1_UNAUTHORIZED =
OAUTH1_BASE + '/RequestToken'
OAUTH1_REDIRECT =
OAUTH1_BASE + '/Authorize'
OAUTH1_ACCESS_TOKEN =
OAUTH1_BASE + '/AccessToken'

Constants included from Connection

Connection::AUTHORIZATION_MIDDLEWARES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Configuration

log, log=, logger, logger=

Methods included from Methods

#create, #delete, #get, #update

Methods included from Attachment

#attachment_connection, #upload_attachment

Methods included from Util

#add_params, #entity_handler, #json_date, #parse_json_date, #snake_to_camel, #standard_date

Methods included from Connection

add_authorization_middleware, #authorized_json_connection, #authorized_multipart_connection, #build_connection, #parse_response_body, #raw_request, #request, #response

Methods included from Connection::OAuth2

#add_oauth2_authorization_middleware, included, #use_oauth2_middleware?

Methods included from Connection::OAuth1

#add_oauth1_authorization_middleware, included, #use_oauth1_middleware?

Constructor Details

#initialize(attributes = {}) ⇒ Api

Returns a new instance of Api.

Raises:



26
27
28
29
30
31
32
33
# File 'lib/xero/api.rb', line 26

def initialize(attributes = {})
  raise Xero::Api::Error, "missing or blank keyword: token" unless attributes.key?(:token) and !attributes[:token].nil?
  attributes = default_attributes.merge!(attributes)
  attributes.each do |attribute, value|
    public_send("#{attribute}=", value)
  end
  @endpoint_url = get_endpoint
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



2
3
4
# File 'lib/xero/api/connection/oauth2.rb', line 2

def access_token
  @access_token
end

#consumer_keyObject

Returns the value of attribute consumer_key.



9
10
11
# File 'lib/xero/api/connection/oauth1.rb', line 9

def consumer_key
  @consumer_key
end

#consumer_secretObject

Returns the value of attribute consumer_secret.



9
10
11
# File 'lib/xero/api/connection/oauth1.rb', line 9

def consumer_secret
  @consumer_secret
end

#endpointObject

Returns the value of attribute endpoint.



21
22
23
# File 'lib/xero/api.rb', line 21

def endpoint
  @endpoint
end

#tokenObject

Returns the value of attribute token.



8
9
10
# File 'lib/xero/api/connection/oauth1.rb', line 8

def token
  @token
end

#token_secretObject

Returns the value of attribute token_secret.



8
9
10
# File 'lib/xero/api/connection/oauth1.rb', line 8

def token_secret
  @token_secret
end

Instance Method Details

#connection(url: endpoint_url) ⇒ Object



41
42
43
# File 'lib/xero/api.rb', line 41

def connection(url: endpoint_url)
  @connection ||= authorized_json_connection(url)
end

#default_attributesObject



35
36
37
38
39
# File 'lib/xero/api.rb', line 35

def default_attributes
  {
    endpoint: :accounting
  }
end

#endpoint_urlObject



45
46
47
# File 'lib/xero/api.rb', line 45

def endpoint_url
  @endpoint_url.dup
end