Class: TokyoApi::Client

Inherits:
Vertebrae::API
  • Object
show all
Defined in:
lib/tokyo_api/client.rb

Instance Method Summary collapse

Instance Method Details

#actionkitObject



3
4
5
# File 'lib/tokyo_api/client.rb', line 3

def actionkit
  @actionkit ||= TokyoApi::Actionkit.new(client: self)
end

#bluestatedigitalObject



7
8
9
# File 'lib/tokyo_api/client.rb', line 7

def bluestatedigital
  @bluestatedigital ||= TokyoApi::Bluestatedigital.new(client: self)
end

#default_optionsObject



24
25
26
27
28
29
30
# File 'lib/tokyo_api/client.rb', line 24

def default_options
  {
    user_agent: 'TokyoApi Gem',
    prefix: '',
    content_type: 'application/json'
  }
end

#expireObject



19
20
21
# File 'lib/tokyo_api/client.rb', line 19

def expire
  @expire ||= TokyoApi::Expire.new(client: self)
end

#identityObject



15
16
17
# File 'lib/tokyo_api/client.rb', line 15

def identity
  @identity ||= TokyoApi::Identity.new(client: self)
end

#krautbusterObject



11
12
13
# File 'lib/tokyo_api/client.rb', line 11

def krautbuster
  @krautbuster ||= TokyoApi::Krautbuster.new(client: self)
end

#request(method, path, params, options) ⇒ Object

:nodoc:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/tokyo_api/client.rb', line 32

def request(method, path, params, options) # :nodoc:
  if !::Vertebrae::Request::METHODS.include?(method)
    raise ArgumentError, "unknown http method: #{method}"
  end

  unless connection.configuration.prefix.blank?
    path =  connection.configuration.prefix + '/' + path
  end

  ::Vertebrae::Base.logger.debug "EXECUTED: #{method} - #{path} with #{params} and #{options}"

  connection.connection.send(method) do |request|

    case method.to_sym
      when *(::Vertebrae::Request::METHODS - ::Vertebrae::Request::METHODS_WITH_BODIES)
        request.url(path, params)
      when *::Vertebrae::Request::METHODS_WITH_BODIES
        request.path = path
        request.body = extract_data_from_params(params) unless params.empty?
    end
  end
end

#setupObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/tokyo_api/client.rb', line 55

def setup
  connection.stack do |builder|
    builder.use Faraday::Request::Multipart
    builder.use Faraday::Request::UrlEncoded
    builder.use Vertebrae::Request::BasicAuth, connection.configuration.authentication if connection.configuration.authenticated?

    builder.use Faraday::Response::Logger if ENV['DEBUG']

    builder.use FaradayMiddleware::Mashify
    builder.use FaradayMiddleware::ParseJson

    builder.use Vertebrae::Response::RaiseError
    builder.adapter connection.configuration.adapter
  end
end