rollbar-api 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b174a393dd39338a440f851db212dd871e8ad4a5
4
- data.tar.gz: 958b809533fa494ff7729ae0fb1fa882e8cc439a
3
+ metadata.gz: de7fea7977ca5a014746909d9e82d7da1130b91f
4
+ data.tar.gz: 1af351ceaa9d3eb1589ad1d0ce79baf5548110ba
5
5
  SHA512:
6
- metadata.gz: ef6be010762ed92e51e895aa5d849032d883acbcf18fb0296dcc1d05d3b9665d9cafd7fdc5be37340deb20ebc94012395fb0604f523640270ac8d1c604c2a70b
7
- data.tar.gz: 335a1d5139c03af4e730bb875b239a991db54a1044bcf6e65cc8925f11b5f3f6c126450a244a31e0785dae5dfc537e66e123d70a71ce7076bc28846f208e5b89
6
+ metadata.gz: 650c9cddc0c41e6bcbd28786a28c034742149f18178bfa5c44af22f05948fdc916d87dc0d0e99126cd052d53ac5b91ffac663bb92c7aa0ab782b454b99d058db
7
+ data.tar.gz: 2046181b08ebdbe7af9e562e31e381204433c99e6341c8c403e5aa0b6c1127c65f677f7df3a8293369ed8180eaba2cd0802d31b91b53347803af8f5bc1495dba
data/README.md CHANGED
@@ -1,7 +1,11 @@
1
- # rollbar-api [![CircleCI](https://circleci.com/gh/wealthsimple/rollbar-api.svg?style=svg)](https://circleci.com/gh/wealthsimple/rollbar-api)
1
+ # rollbar-api [![CircleCI](https://circleci.com/gh/wealthsimple/rollbar-api.svg?style=svg)](https://circleci.com/gh/wealthsimple/rollbar-api) [![](https://img.shields.io/gem/v/rollbar-api.svg)](https://rubygems.org/gems/rollbar-api)
2
2
 
3
3
  Rubygem for accessing Rollbar's full REST and RQL APIs.
4
4
 
5
+ The [official rollbar rubygem](https://github.com/rollbar/rollbar-gem) only covers a small portion of the API, whereas this rubygem provides an interface over all API endpoints, including the Rollbar Query Language (RQL) endpoints.
6
+
7
+ This gem aims to be future-compatible by not hard-coding any endpoints or request structures. See https://rollbar.com/docs/api/ for a full reference of all API requests and responses.
8
+
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile and run `bundle` to install:
@@ -10,9 +14,9 @@ Add this line to your application's Gemfile and run `bundle` to install:
10
14
  gem 'rollbar-api'
11
15
  ```
12
16
 
13
- ## Usage
17
+ ## Usage (Project-level APIs)
14
18
 
15
- First, generate read-only access tokens for each project you need access to by navigating to **Settings** > **Project Access Tokens** and clicking **Add new access token**.
19
+ First, generate access tokens for each project you need access to by navigating to **Settings** > **Project Access Tokens** and clicking **Add new access token**. Unless you specifically need write access, it is recommended that you generate a read-only token.
16
20
 
17
21
  Next, configure each project:
18
22
 
@@ -21,11 +25,11 @@ Next, configure each project:
21
25
  require 'rollbar-api'
22
26
 
23
27
  # Add as many projects as you need. Each should have a unique access token.
24
- RollbarApi::Project.add("my-project", ENV["MY_PROJECT_ACCESS_TOKEN"])
25
- RollbarApi::Project.add("other-project", ENV["OTHER_PROJECT_ACCESS_TOKEN"])
28
+ RollbarApi::Project.configure("my-project", ENV["MY_PROJECT_ACCESS_TOKEN"])
29
+ RollbarApi::Project.configure("other-project", ENV["OTHER_PROJECT_ACCESS_TOKEN"])
26
30
  ```
27
31
 
28
- ### REST API
32
+ ### Making API Requests
29
33
 
30
34
  You can make HTTP `GET` calls to fetch items, deploys, occurrences, and so on by finding any project you added in the configuration and calling `.get` with the API endpoint:
31
35
 
@@ -42,6 +46,8 @@ top_items = RollbarApi::Project.find("my-project").get("/api/1/reports/top_activ
42
46
  })
43
47
  ```
44
48
 
49
+ If you need to make an HTTP `POST`, `DELETE`, and so on, just replace `.get` with `.post`, `.delete`, and so forth.
50
+
45
51
  ### RQL Queries
46
52
 
47
53
  You can also run RQL queries:
@@ -62,7 +68,27 @@ if rql_job.result.status == "success"
62
68
  end
63
69
  ```
64
70
 
65
- See https://rollbar.com/docs/api/ for a full reference of API requests and responses.
71
+ ## Usage (Account-level APIs)
72
+
73
+ First, generate access tokens for each account you need access to by navigating to https://rollbar.com/settings/accounts/ACCOUNT_NAME/access_tokens/ and clicking **Add new access token**. Unless you specifically need write access, it is recommended that you generate a read-only token.
74
+
75
+ Next, configure each account:
76
+
77
+ ```ruby
78
+ # config/initializers/rollbar-api.rb in a Rails project
79
+ require 'rollbar-api'
80
+
81
+ # Add as many accounts as you need (normally just one). Each should have a unique access token.
82
+ RollbarApi::Account.configure("my-organization", ENV["ROLLBAR_ACCOUNT_ACCESS_TOKEN"])
83
+ ```
84
+
85
+ ### Making API Requests
86
+
87
+ Making API requests through Account-level APIs works similarly to project-level API. Here's an example that fetches all Rollbar user details for your account:
88
+
89
+ ```ruby
90
+ users = RollbarApi::Account.find("my-organization").get("/api/1/users")
91
+ ```
66
92
 
67
93
  ## Development
68
94
 
@@ -0,0 +1,14 @@
1
+ require "dotenv/load"
2
+ require "pp"
3
+ require "bundler/setup"
4
+ require "rollbar-api"
5
+
6
+ account_name = ENV["ROLLBAR_ACCOUNT_NAME"] or raise "Must specify ROLLBAR_ACCOUNT_NAME in .env"
7
+ account_access_token = ENV["ROLLBAR_ACCOUNT_ACCESS_TOKEN"] or raise "Must specify ROLLBAR_ACCOUNT_ACCESS_TOKEN in .env"
8
+
9
+ RollbarApi::Account.configure(account_name, account_access_token)
10
+
11
+ users = RollbarApi::Account.find(account_name).get("/api/1/users")
12
+ users.result.users.each do |user|
13
+ p [user.username, user.email]
14
+ end
@@ -6,7 +6,7 @@ require "rollbar-api"
6
6
  project_name = ENV["ROLLBAR_PROJECT_NAME"] or raise "Must specify ROLLBAR_PROJECT_NAME in .env"
7
7
  project_access_token = ENV["ROLLBAR_PROJECT_ACCESS_TOKEN"] or raise "Must specify ROLLBAR_PROJECT_ACCESS_TOKEN in .env"
8
8
 
9
- RollbarApi::Project.add(project_name, project_access_token)
9
+ RollbarApi::Project.configure(project_name, project_access_token)
10
10
 
11
11
  # Fetch all items
12
12
  items = RollbarApi::Project.find(project_name).get("/api/1/items")
@@ -6,7 +6,7 @@ require "rollbar-api"
6
6
  project_name = ENV["ROLLBAR_PROJECT_NAME"] or raise "Must specify ROLLBAR_PROJECT_NAME in .env"
7
7
  project_access_token = ENV["ROLLBAR_PROJECT_ACCESS_TOKEN"] or raise "Must specify ROLLBAR_PROJECT_ACCESS_TOKEN in .env"
8
8
 
9
- RollbarApi::Project.add(project_name, project_access_token)
9
+ RollbarApi::Project.configure(project_name, project_access_token)
10
10
 
11
11
  # Create the job
12
12
  rql_job = RollbarApi::Project.find(project_name).post("/api/1/rql/jobs", {
@@ -6,7 +6,7 @@ require "rollbar-api"
6
6
  project_name = ENV["ROLLBAR_PROJECT_NAME"] or raise "Must specify ROLLBAR_PROJECT_NAME in .env"
7
7
  project_access_token = ENV["ROLLBAR_PROJECT_ACCESS_TOKEN"] or raise "Must specify ROLLBAR_PROJECT_ACCESS_TOKEN in .env"
8
8
 
9
- RollbarApi::Project.add(project_name, project_access_token)
9
+ RollbarApi::Project.configure(project_name, project_access_token)
10
10
 
11
11
  top_active_items = RollbarApi::Project.find(project_name).get("/api/1/reports/top_active_items", {
12
12
  hours: "24",
@@ -4,6 +4,7 @@ require "faraday"
4
4
  require "json"
5
5
  require "recursive-open-struct"
6
6
 
7
+ require "rollbar-api/account"
7
8
  require "rollbar-api/project"
8
9
  require "rollbar-api/request"
9
10
  require "rollbar-api/resource"
@@ -0,0 +1,40 @@
1
+ module RollbarApi
2
+ class Account
3
+ @@accounts = {}
4
+
5
+ def self.configure(account_name, account_access_token)
6
+ @@accounts[account_name] = account_access_token
7
+ end
8
+
9
+ def self.find(account_name)
10
+ account_access_token = @@accounts[account_name]
11
+ new(account_name, account_access_token) if account_access_token.present?
12
+ end
13
+
14
+ def self.all
15
+ @@accounts.map { |account_name, _| find(account_name) }
16
+ end
17
+
18
+ def self.delete_all
19
+ @@accounts = {}
20
+ end
21
+
22
+ attr_reader :name, :access_token
23
+ def initialize(name, access_token)
24
+ @name = name
25
+ @access_token = access_token
26
+ end
27
+
28
+ %i(get post put delete head patch).each do |http_method|
29
+ define_method(http_method) do |path, params = {}|
30
+ params[:access_token] = access_token
31
+ response = Request.new(method: http_method, path: path, params: params).execute
32
+ if response.is_a?(Array)
33
+ response.map { |r| Resource.new(r) }
34
+ else
35
+ Resource.new(response)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -2,7 +2,7 @@ module RollbarApi
2
2
  class Project
3
3
  @@projects = {}
4
4
 
5
- def self.add(project_name, project_access_token)
5
+ def self.configure(project_name, project_access_token)
6
6
  @@projects[project_name] = project_access_token
7
7
  end
8
8
 
@@ -1,3 +1,3 @@
1
1
  module RollbarApi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollbar-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Graham
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-05 00:00:00.000000000 Z
11
+ date: 2017-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -178,10 +178,12 @@ files:
178
178
  - Rakefile
179
179
  - bin/console
180
180
  - bin/setup
181
+ - examples/list_account_users.rb
181
182
  - examples/list_items.rb
182
183
  - examples/rql_query.rb
183
184
  - examples/top_active_items.rb
184
185
  - lib/rollbar-api.rb
186
+ - lib/rollbar-api/account.rb
185
187
  - lib/rollbar-api/project.rb
186
188
  - lib/rollbar-api/request.rb
187
189
  - lib/rollbar-api/resource.rb