Class: Gorilla::VanillaClient

Inherits:
Object
  • Object
show all
Defined in:
lib/gorilla/vanilla_client.rb

Direct Known Subclasses

Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}, &block) ⇒ VanillaClient

Returns a new instance of VanillaClient.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/gorilla/vanilla_client.rb', line 6

def initialize(opts={}, &block)
  options = config.api.to_h.merge(opts)

  @connection = Faraday.new(options[:url]) do |conn|
    conn.request :multipart
    conn.request :user_agent, config.user_agent
    conn.request :url_encoded
    yield(conn, options) if block_given?
    conn.response :json, content_type: /\bjson$/
    conn.adapter *config.client_adapter
  end
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



4
5
6
# File 'lib/gorilla/vanilla_client.rb', line 4

def connection
  @connection
end

Instance Method Details

#configObject



35
36
37
# File 'lib/gorilla/vanilla_client.rb', line 35

def config
  Gorilla.configuration
end

#delete(path, params = {}) ⇒ Object



31
32
33
# File 'lib/gorilla/vanilla_client.rb', line 31

def delete(path, params={})
  request(:delete, path, params)
end

#get(path, params = {}) ⇒ Object



19
20
21
# File 'lib/gorilla/vanilla_client.rb', line 19

def get(path, params={})
  request(:get, path, params)
end

#post(path, params = {}) ⇒ Object



23
24
25
# File 'lib/gorilla/vanilla_client.rb', line 23

def post(path, params={})
  request(:post, path, params)
end

#put(path, params = {}) ⇒ Object



27
28
29
# File 'lib/gorilla/vanilla_client.rb', line 27

def put(path, params={})
  request(:put, path, params)
end