Class: Bugsnag::Api::Client

Inherits:
Object
  • Object
show all
Includes:
Collaborators, Comments, CurrentUser, Errors, EventFields, Events, Organizations, Pivots, Projects, Trends
Defined in:
lib/bugsnag/api/client.rb,
lib/bugsnag/api/client/errors.rb,
lib/bugsnag/api/client/events.rb,
lib/bugsnag/api/client/pivots.rb,
lib/bugsnag/api/client/trends.rb,
lib/bugsnag/api/client/comments.rb,
lib/bugsnag/api/client/projects.rb,
lib/bugsnag/api/client/currentuser.rb,
lib/bugsnag/api/client/eventfields.rb,
lib/bugsnag/api/client/collaborators.rb,
lib/bugsnag/api/client/organizations.rb

Overview

Client for the Bugsnag API

Defined Under Namespace

Modules: Collaborators, Comments, CurrentUser, Errors, EventFields, Events, Organizations, Pivots, Projects, Trends

Constant Summary collapse

CONVENIENCE_HEADERS =

Header keys that can be passed in options hash to #get,#head

Set.new([:accept, :content_type])

Instance Method Summary collapse

Methods included from Comments

#comment, #comments, #create_comment, #delete_comment, #update_comment

Methods included from Trends

#trends_buckets, #trends_resolution

Methods included from Pivots

#pivot_values, #pivots

Methods included from Events

#delete_event, #error_events, #event, #events, #latest_event

Methods included from Errors

#delete_errors, #error, #errors, #update_errors

Methods included from CurrentUser

#organizations, #projects

Methods included from EventFields

#create_event_field, #delete_event_field, #event_fields, #update_event_field

Methods included from Projects

#create_project, #delete_project, #project, #regenerate_api_key, #update_project

Methods included from Collaborators

#collaborator, #collaborators, #delete_collaborator, #invite_collaborators, #update_collaborator_permissions, #view_collaborator_projects

Methods included from Organizations

#create_organization, #delete_organization, #organization, #update_organization

Constructor Details

#initialize(options = {}) {|configuration| ... } ⇒ Client

Returns a new instance of Client

Yields:



35
36
37
38
# File 'lib/bugsnag/api/client.rb', line 35

def initialize(options = {}, &block)
  configuration.load(options)
  yield(configuration) if block_given?
end

Instance Method Details

#basic_authenticated?Boolean

Indicates if the client was supplied Basic Auth username and password



134
135
136
# File 'lib/bugsnag/api/client.rb', line 134

def basic_authenticated?
  !!(configuration.email && configuration.password)
end

#configurationBugsnag::Api::Configuration

Get client's configuration options

Returns:



49
50
51
# File 'lib/bugsnag/api/client.rb', line 49

def configuration
  @configuration ||= Configuration.new
end

#configure {|configuration| ... } ⇒ Object

Set configuration options using a block

Yields:



41
42
43
44
# File 'lib/bugsnag/api/client.rb', line 41

def configure
  yield(configuration) if block_given?
  reset_agent
end

#deep_merge(l_hash, r_hash) ⇒ Hash

Merges hashes together cleanly, favouring RHS values

Returns:

  • (Hash)


149
150
151
152
153
154
155
156
157
# File 'lib/bugsnag/api/client.rb', line 149

def deep_merge(l_hash, r_hash)
  l_hash.merge(r_hash) do |_key, l_val, r_val|
    if l_val.is_a?(Hash) && r_val.is_a?(Hash)
      deep_merge(l_val, r_val)
    else
      r_val
    end
  end
end

#delete(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP DELETE request

Parameters:

  • url (String)

    The path, relative to #endpoint

  • options (Hash) (defaults to: {})

    Query and header params for request

Returns:

  • (Sawyer::Resource)


85
86
87
# File 'lib/bugsnag/api/client.rb', line 85

def delete(url, options = {})
  request :delete, url, options
end

#get(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP GET request

Parameters:

  • url (String)

    The path, relative to #endpoint

  • options (Hash) (defaults to: {})

    Query and header params for request

Returns:

  • (Sawyer::Resource)


58
59
60
# File 'lib/bugsnag/api/client.rb', line 58

def get(url, options = {})
  request :get, url, parse_query_and_convenience_headers(options)
end

#last_responseSawyer::Response

Response for last HTTP request

Returns:

  • (Sawyer::Response)


125
126
127
# File 'lib/bugsnag/api/client.rb', line 125

def last_response
  @last_response if defined? @last_response
end

#paginate(url, options = {}, &block) ⇒ Sawyer::Resource

Make one or more HTTP GET requests, optionally fetching the next page of results from URL in Link response header based on value in #auto_paginate.

Parameters:

  • url (String)

    The path, relative to #endpoint

  • options (Hash) (defaults to: {})

    Query and header params for request

  • block (Block)

    Block to perform the data concatination of the multiple requests. The block is called with two parameters, the first contains the contents of the requests so far and the second parameter contains the latest response.

Returns:

  • (Sawyer::Resource)


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/bugsnag/api/client.rb', line 100

def paginate(url, options = {}, &block)
  opts = parse_query_and_convenience_headers(options.dup)
  if configuration.auto_paginate || configuration.per_page
    opts[:query][:per_page] ||=  configuration.per_page || (configuration.auto_paginate ? 100 : nil)
  end

  data = request(:get, url, opts)

  if configuration.auto_paginate
    while @last_response.rels[:next]
      @last_response = @last_response.rels[:next].get
      if block_given?
        yield(data, @last_response)
      else
        data.concat(@last_response.data) if @last_response.data.is_a?(Array)
      end
    end
  end

  data
end

#patch(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP PATCH request

Parameters:

  • url (String)

    The path, relative to #endpoint

  • options (Hash) (defaults to: {})

    Body and header params for request

Returns:

  • (Sawyer::Resource)


76
77
78
# File 'lib/bugsnag/api/client.rb', line 76

def patch(url, options = {})
  request :patch, url, options
end

#post(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP POST request

Parameters:

  • url (String)

    The path, relative to #endpoint

  • options (Hash) (defaults to: {})

    Body and header params for request

Returns:

  • (Sawyer::Resource)


67
68
69
# File 'lib/bugsnag/api/client.rb', line 67

def post(url, options = {})
  request :post, url, options
end

#token_authenticated?Boolean

Indicates if the client was supplied an auth token



142
143
144
# File 'lib/bugsnag/api/client.rb', line 142

def token_authenticated?
  !!configuration.auth_token
end