Class: TijuanaClient::Client

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

Instance Method Summary collapse

Instance Method Details

#default_optionsObject



13
14
15
16
17
18
19
# File 'lib/tijuana_client/client.rb', line 13

def default_options
  {
    user_agent: 'TijuanaClient',
    prefix: '',
    content_type: 'application/x-www-form-urlencoded'
  }
end

#post_json_request(path, params) ⇒ Object



7
8
9
10
11
# File 'lib/tijuana_client/client.rb', line 7

def post_json_request(path, params)
  p = {}
  p['data'] = params.to_json
  post_request(path, p)
end

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

:nodoc:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tijuana_client/client.rb', line 21

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

  path =  connection.configuration.prefix + '/' + path

  ::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.body = params.delete('data') if params.has_key?('data')
        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



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tijuana_client/client.rb', line 43

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 Vertebrae::Response::RaiseError
    builder.adapter connection.configuration.adapter
  end
end

#userObject



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

def user
  @user ||= TijuanaClient::User.new(client: self)
end