Class: Bugsnag::Api::Client

Inherits:
Object
  • Object
show all
Includes:
Collaborators, Comments, CurrentUser, Errors, EventFields, Events, Organizations, Pivots, Projects, Releases, Stability, 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/releases.rb,
lib/bugsnag/api/client/stability.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, Releases, Stability, 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 Releases

#release, #releases, #releases_in_group

Methods included from Stability

#stability_trend

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, #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:



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

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



140
141
142
# File 'lib/bugsnag/api/client.rb', line 140

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

#configurationBugsnag::Api::Configuration

Get client's configuration options

Returns:



55
56
57
# File 'lib/bugsnag/api/client.rb', line 55

def configuration
  @configuration ||= Configuration.new
end

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

Set configuration options using a block

Yields:



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

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)


155
156
157
158
159
160
161
162
163
# File 'lib/bugsnag/api/client.rb', line 155

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)


91
92
93
# File 'lib/bugsnag/api/client.rb', line 91

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)


64
65
66
# File 'lib/bugsnag/api/client.rb', line 64

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)


131
132
133
# File 'lib/bugsnag/api/client.rb', line 131

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)


106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/bugsnag/api/client.rb', line 106

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)


82
83
84
# File 'lib/bugsnag/api/client.rb', line 82

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)


73
74
75
# File 'lib/bugsnag/api/client.rb', line 73

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

#token_authenticated?Boolean

Indicates if the client was supplied an auth token



148
149
150
# File 'lib/bugsnag/api/client.rb', line 148

def token_authenticated?
  !!configuration.auth_token
end