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, RequestFailed, Resource, TooManyRequests, UrlAndPayloadIdMismatch

Constant Summary collapse

VERSION =
"0.3.0"
@@api_key =
nil
@@host =
nil
@@verbose =

Verbose will do $stdout.puts. That’s useful on a Rails console in development, where logger output is ommited.

nil
@@logger =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, verbose: nil, logger: nil) ⇒ Apisync

Returns a new instance of Apisync.

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
# File 'lib/apisync.rb', line 24

def initialize(api_key: nil, verbose: nil, logger: nil)
  @api_key = api_key || @@api_key
  @host = @@host
  @verbose = verbose || @@verbose

  @logger = logger || @@logger

  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



34
35
36
37
38
39
40
41
42
43
# File 'lib/apisync.rb', line 34

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

  Apisync::Resource.new(name, options)
end

Instance Attribute Details

#verboseObject

Returns the value of attribute verbose.



22
23
24
# File 'lib/apisync.rb', line 22

def verbose
  @verbose
end

Class Method Details

.api_key=(value) ⇒ Object



49
50
51
# File 'lib/apisync.rb', line 49

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

.host=(value) ⇒ Object



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

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

.loggerObject



61
62
63
# File 'lib/apisync.rb', line 61

def self.logger
  @@logger
end

.logger=(value) ⇒ Object



57
58
59
# File 'lib/apisync.rb', line 57

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

.verboseObject



65
66
67
# File 'lib/apisync.rb', line 65

def self.verbose
  @@verbose
end

.verbose=(value) ⇒ Object



53
54
55
# File 'lib/apisync.rb', line 53

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