Class: Catch::Client

Inherits:
Object
  • Object
show all
Includes:
Comment, Media, Note, Place, Search, Tag, User
Defined in:
lib/catch/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from User

#user

Methods included from Tag

#tags

Methods included from Search

#search

Methods included from Place

#add_place, #delete_place, #modify_place, #place, #places

Methods included from Note

#add_note, #delete_note, #modify_note, #note, #notes

Methods included from Media

#add_media, #delete_media, #media

Methods included from Comment

#add_comment, #comment, #comments, #delete_comment, #modify_comment

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



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

def initialize(options={})
  @api_url  = "https://api.catch.com/v2"
  @username = options[:username] || Catch.username
  password  = options[:password] || Catch.password
  connection.basic_auth(@username, password)
  media_connection.basic_auth(@username, password)
end

Instance Attribute Details

#api_urlObject (readonly)

Returns the value of attribute api_url.



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

def api_url
  @api_url
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#connectionFaraday::Connection

Raw HTTP connection, either Faraday::Connection

Returns:

  • (Faraday::Connection)


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

def connection
  @connection ||= Faraday.new(:url => @api_url, :headers => default_headers) do |builder|
    builder.request :multipart
    builder.request :url_encoded
    builder.request :json
    builder.adapter Faraday.default_adapter
    builder.use Faraday::Response::Mashify
    builder.use Faraday::Response::ParseJson
  end
end

#media_connectionFaraday::Connection

Raw HTTP connection, either Faraday::Connection

media_connection is used for calls which do not return JSON data.

Returns:

  • (Faraday::Connection)


40
41
42
43
44
45
46
47
# File 'lib/catch/client.rb', line 40

def media_connection
  @media_connection ||= Faraday.new(:url => @api_url, :headers => default_headers) do |builder|
    builder.request :multipart
    builder.request :url_encoded
    builder.adapter Faraday.default_adapter
    builder.use Faraday::Response::Mashify
  end
end