Class: Camdram::HTTP

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/camdram/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_token=(value) ⇒ Object (writeonly)

Sets the attribute api_token

Parameters:

  • value

    the value to set the attribute api_token to.



9
10
11
# File 'lib/camdram/http.rb', line 9

def api_token=(value)
  @api_token = value
end

#base_urlString

Returns the API URL that each HTTP request is sent to

Returns:

  • (String)

    The API hostname to send requests to.



40
41
42
# File 'lib/camdram/http.rb', line 40

def base_url
  @base_url ||= Camdram::BASE_URL
end

#user_agentString

Returns the user agent header sent in each HTTP request

Returns:

  • (String)

    The user agent header to send with HTTP requests.



47
48
49
# File 'lib/camdram/http.rb', line 47

def user_agent
  @user_agent ||= "Camdram Ruby v#{Camdram::VERSION}"
end

Instance Method Details

#api_token?Boolean

Returns true if the API access token is set

Returns:

  • (Boolean)

    Whether the API token is set or not.



26
27
28
# File 'lib/camdram/http.rb', line 26

def api_token?
  !@api_token.nil? && !(blank?(@api_token))
end

#get(url_slug, max_redirects = 10) ⇒ String

Sends a HTTP-get request to the Camdram API

Parameters:

  • url_slug (String)

    The URL slug to send the request to.

  • max_redirects (Integer) (defaults to: 10)

    The maximum number of redirects.

Returns:

  • (String)

Raises:



17
18
19
20
21
# File 'lib/camdram/http.rb', line 17

def get(url_slug, max_redirects = 10)
  url = base_url + url_slug
  uri = URI(url)
  inner_get(uri, max_redirects)
end

#user_agent?Boolean

Returns true if the User Agent string is set

Returns:

  • (Boolean)

    Whether the User Agent string is set or not.



33
34
35
# File 'lib/camdram/http.rb', line 33

def user_agent?
  !@user_agent.nil? && !(blank?(@user_agent))
end