Class: StatusCake::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/statuscake/client.rb

Constant Summary collapse

ENDPOINT =
'https://app.statuscake.com'
USER_AGENT =
"Ruby StatusCake Client #{StatusCake::VERSION}"
DEFAULT_ADAPTERS =
[
  Faraday::Adapter::NetHttp,
  Faraday::Adapter::Test
]
OPTIONS =
[
  :API,
  :Username,
]
APIs =
{
  '/API/Alerts'               => {:method => :get},
  '/API/ContactGroups/Update' => {:method => :put},
  '/API/ContactGroups'        => {:method => :get},
  '/API/Tests/Checks'         => {:method => :get},
  '/API/Tests/Periods'        => {:method => :get},
  '/API/Tests'                => {:method => :get},
  '/API/Tests/Details'        => {:method => :get},
  # Delete test when HTTP method is "DELETE"
  # see https://www.statuscake.com/api/Tests/Deleting%20a%20Test.md
  '/API/Tests/Update'         => {:method => :put},
  '/API/Locations/json'       => {:method => :get, :alias => :locations},
  '/API/Locations/txt'        => {:method => :get},
  '/API/Locations/xml'        => {:method => :get},
  '/API/Auth'                 => {:method => :get},
}

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



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

def initialize(options)
  @options = {}

  OPTIONS.each do |key|
    @options[key] = options.delete(key)
  end

  options[:url] ||= ENDPOINT

  @conn = Faraday.new(options) do |faraday|
    faraday.request  :url_encoded
    faraday.response :json, :content_type => /\bjson$/
    faraday.response :raise_error

    yield(faraday) if block_given?

    unless DEFAULT_ADAPTERS.any? {|i| faraday.builder.handlers.include?(i) }
      faraday.adapter Faraday.default_adapter
    end
  end

  @conn.headers[:user_agent] = USER_AGENT
end