Class: Apisync

Inherits:
Object
  • Object
show all
Defined in:
lib/apisync.rb,
lib/apisync/version.rb,
lib/apisync/http/url.rb,
lib/apisync/resource.rb,
lib/apisync/exceptions.rb,
lib/apisync/http_client.rb,
lib/apisync/http/query_string.rb

Defined Under Namespace

Modules: Http Classes: Exception, HttpClient, InvalidFilter, Resource, TooManyRequests, UrlAndPayloadIdMismatch

Constant Summary collapse

VERSION =
"0.1.5"
@@api_key =
nil
@@host =
nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil) ⇒ Apisync

Returns a new instance of Apisync.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
# File 'lib/apisync.rb', line 15

def initialize(api_key: nil)
  @api_key = api_key || @@api_key
  @host = @@host

  raise ArgumentError, "missing keyword: api_key" if @api_key.nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, args = {}, &block) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/apisync.rb', line 22

def method_missing(name, args = {}, &block)
  # overrides the instance api_key as `authorization`
  options = {
    host: @host
  }.merge(args).merge(api_key: @api_key)
  Apisync::Resource.new(name, options)
end

Class Method Details

.api_key=(value) ⇒ Object



34
35
36
# File 'lib/apisync.rb', line 34

def self.api_key=(value)
  @@api_key = value
end

.host=(value) ⇒ Object



30
31
32
# File 'lib/apisync.rb', line 30

def self.host=(value)
  @@host = host
end