rollbar-api 0.2.1 → 0.4.1

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
- SHA1:
3
- metadata.gz: b4dfed794d59202349e5075a77d9c2221475e452
4
- data.tar.gz: eb1f0802e899e60db31ebeb38ded8caf7f732c18
2
+ SHA256:
3
+ metadata.gz: cb40f1378bac899e1145acb3ac7f53306441009a9a7755eb695216d4eee2789b
4
+ data.tar.gz: 5126b037b0cec8efd7d427489ab9ccbf40fc0c04f26c95e969ac552ce13050b5
5
5
  SHA512:
6
- metadata.gz: 20ea39b0bec19e0767654ee620c4968253faeee93f345bad04d5044cd5f8ae16207c6e5a9c35741783ef5dd8302fcad70954f1db92dd31d66f13f81572ec2152
7
- data.tar.gz: ddcae24799fc9e1b97de51001c286add6a7458ebac82a1fcbc6bf49bf1c80f7c78c99f4d726274f052ccbb58b8e31a5eeefa38d17f51b0805902382145be4b76
6
+ metadata.gz: 52369017d084475f588ed01a980227d34a9180d93f6169e76d96f9293724f55aba2a7ad9b645d85c0543bee80f72efc4945610da0aa6c01fcc94991030101ebe
7
+ data.tar.gz: d8cb7dbd5c01d5900ec49db6bb25b107b44b15af598f88ae7811d3379cb79bd8451e614df224982d39d314bab1cf1cb39ca2d01e9997cb45c643e963d7f18c9f
@@ -0,0 +1 @@
1
+ * @wealthsimple/developer-tools
@@ -0,0 +1,31 @@
1
+ ---
2
+ name: Pipeline
3
+ on: push
4
+ jobs:
5
+ build:
6
+ name: Build
7
+ runs-on: ubuntu-20.04
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - uses: ruby/setup-ruby@v1
11
+ with:
12
+ bundler-cache: true
13
+ - name: Lint
14
+ run: bundle exec rubocop
15
+ - name: Test
16
+ run: bundle exec rspec
17
+ - name: Release the gem
18
+ if: ${{ github.ref == 'refs/heads/main' }}
19
+ run: |
20
+ mkdir -p ~/.gem
21
+ cat << EOF > ~/.gem/credentials
22
+ ---
23
+ :github: Bearer ${GITHUB_TOKEN}
24
+ :rubygems_api_key: ${RUBYGEMS_API_KEY}
25
+ EOF
26
+ chmod 0600 ~/.gem/credentials
27
+ git config user.email "noreply@wealthsimple.com"
28
+ git config user.name "Wolfbot"
29
+ bundle exec rake release
30
+ env:
31
+ RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ inherit_gem:
2
+ ws-style:
3
+ - default.yml
4
+
5
+ Naming/FileName:
6
+ Exclude:
7
+ - lib/rollbar-api.rb
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.3
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in rollbar-api.gemspec
4
6
  gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,119 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rollbar-api (0.4.1)
5
+ activesupport (>= 4)
6
+ faraday (< 1.0)
7
+ recursive-open-struct
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (6.1.3.1)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 1.6, < 2)
15
+ minitest (>= 5.1)
16
+ tzinfo (~> 2.0)
17
+ zeitwerk (~> 2.3)
18
+ addressable (2.7.0)
19
+ public_suffix (>= 2.0.2, < 5.0)
20
+ ast (2.4.2)
21
+ concurrent-ruby (1.1.8)
22
+ crack (0.4.5)
23
+ rexml
24
+ diff-lcs (1.4.4)
25
+ dotenv (2.7.6)
26
+ faraday (0.17.4)
27
+ multipart-post (>= 1.2, < 3)
28
+ hashdiff (1.0.1)
29
+ i18n (1.8.10)
30
+ concurrent-ruby (~> 1.0)
31
+ minitest (5.14.4)
32
+ multipart-post (2.1.1)
33
+ parallel (1.20.1)
34
+ parser (3.0.1.1)
35
+ ast (~> 2.4.1)
36
+ public_suffix (4.0.6)
37
+ rack (2.2.3)
38
+ rainbow (3.0.0)
39
+ rake (10.5.0)
40
+ recursive-open-struct (1.1.3)
41
+ regexp_parser (2.1.1)
42
+ rexml (3.2.5)
43
+ rspec (3.10.0)
44
+ rspec-core (~> 3.10.0)
45
+ rspec-expectations (~> 3.10.0)
46
+ rspec-mocks (~> 3.10.0)
47
+ rspec-collection_matchers (1.2.0)
48
+ rspec-expectations (>= 2.99.0.beta1)
49
+ rspec-core (3.10.1)
50
+ rspec-support (~> 3.10.0)
51
+ rspec-expectations (3.10.1)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.10.0)
54
+ rspec-its (1.3.0)
55
+ rspec-core (>= 3.0.0)
56
+ rspec-expectations (>= 3.0.0)
57
+ rspec-mocks (3.10.2)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.10.0)
60
+ rspec-support (3.10.2)
61
+ rspec_junit_formatter (0.4.1)
62
+ rspec-core (>= 2, < 4, != 2.12.0)
63
+ rubocop (1.13.0)
64
+ parallel (~> 1.10)
65
+ parser (>= 3.0.0.0)
66
+ rainbow (>= 2.2.2, < 4.0)
67
+ regexp_parser (>= 1.8, < 3.0)
68
+ rexml
69
+ rubocop-ast (>= 1.2.0, < 2.0)
70
+ ruby-progressbar (~> 1.7)
71
+ unicode-display_width (>= 1.4.0, < 3.0)
72
+ rubocop-ast (1.5.0)
73
+ parser (>= 3.0.1.1)
74
+ rubocop-performance (1.11.1)
75
+ rubocop (>= 1.7.0, < 2.0)
76
+ rubocop-ast (>= 0.4.0)
77
+ rubocop-rails (2.9.1)
78
+ activesupport (>= 4.2.0)
79
+ rack (>= 1.1)
80
+ rubocop (>= 0.90.0, < 2.0)
81
+ rubocop-rspec (2.3.0)
82
+ rubocop (~> 1.0)
83
+ rubocop-ast (>= 1.1.0)
84
+ rubocop-vendor (0.6.0)
85
+ rubocop (>= 0.53.0)
86
+ ruby-progressbar (1.11.0)
87
+ tzinfo (2.0.4)
88
+ concurrent-ruby (~> 1.0)
89
+ unicode-display_width (2.0.0)
90
+ webmock (3.12.2)
91
+ addressable (>= 2.3.6)
92
+ crack (>= 0.3.2)
93
+ hashdiff (>= 0.4.0, < 2.0.0)
94
+ ws-style (6.9.0)
95
+ rubocop (>= 1.12.1)
96
+ rubocop-performance (>= 1.10.2)
97
+ rubocop-rails (>= 2.9.1)
98
+ rubocop-rspec (>= 2.2.0)
99
+ rubocop-vendor (>= 0.6.0)
100
+ zeitwerk (2.4.2)
101
+
102
+ PLATFORMS
103
+ ruby
104
+
105
+ DEPENDENCIES
106
+ bundler
107
+ dotenv
108
+ rake (~> 10.0)
109
+ rollbar-api!
110
+ rspec (~> 3.0)
111
+ rspec-collection_matchers
112
+ rspec-its
113
+ rspec_junit_formatter (~> 0.2)
114
+ rubocop
115
+ webmock (~> 3.0)
116
+ ws-style
117
+
118
+ BUNDLED WITH
119
+ 2.2.16
data/README.md CHANGED
@@ -1,4 +1,5 @@
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)
1
+ # rollbar-api
2
+ [![GitHub Actions Badge](https://github.com/wealthsimple/rollbar-api/actions/workflows/main.yml/badge.svg)](https://github.com/wealthsimple/rollbar-api/actions)
2
3
 
3
4
  Rubygem for accessing Rollbar's full REST and RQL APIs.
4
5
 
@@ -22,7 +23,7 @@ Next, configure each project:
22
23
 
23
24
  ```ruby
24
25
  # config/initializers/rollbar-api.rb in a Rails project
25
- require 'rollbar-api'
26
+ require 'rollbar_api'
26
27
 
27
28
  # Add as many projects as you need. Each should have a unique access token.
28
29
  RollbarApi::Project.configure("my-project", ENV["MY_PROJECT_ACCESS_TOKEN"])
@@ -35,13 +36,11 @@ You can make HTTP `GET` calls to fetch items, deploys, occurrences, and so on by
35
36
 
36
37
  ```ruby
37
38
  project = RollbarApi::Project.find("my-project")
38
- items = project.get("/api/1/items/")
39
- ```
40
39
 
41
- Specify query parameters by passing them in as a hash:
40
+ # List recent items:
41
+ items = project.get("/api/1/items/")
42
42
 
43
- ```ruby
44
- project = RollbarApi::Project.find("my-project")
43
+ # Specify query parameters by passing them in as a hash:
45
44
  top_items = project.get("/api/1/reports/top_active_items", {
46
45
  hours: "24",
47
46
  environments: "production,staging",
@@ -55,16 +54,17 @@ If you need to make an HTTP `POST`, `DELETE`, and so on, just replace `.get` wit
55
54
  You can also run RQL queries:
56
55
 
57
56
  ```ruby
58
- # Create a job
59
57
  project = RollbarApi::Project.find("my-project")
58
+
59
+ # Create a job
60
60
  rql_job = project.post("/api/1/rql/jobs", {
61
61
  query_string: "select * from item_occurrence where item.counter=1",
62
62
  })
63
63
 
64
- # Check its status
64
+ # Check job status
65
65
  rql_job = project.get("/api/1/rql/job/#{rql_job.result.id}")
66
66
 
67
- # If it succeeded, get the RQL result
67
+ # If job succeeded, get the RQL result
68
68
  if rql_job.result.status == "success"
69
69
  rql_result = project.get("/api/1/rql/job/#{rql_job.result.id}/result")
70
70
  p rql_result
@@ -78,8 +78,8 @@ First, generate access tokens for each account you need access to by navigating
78
78
  Next, configure each account:
79
79
 
80
80
  ```ruby
81
- # config/initializers/rollbar-api.rb in a Rails project
82
- require 'rollbar-api'
81
+ # config/initializers/rollbar_api.rb in a Rails project
82
+ require 'rollbar_api'
83
83
 
84
84
  # Add as many accounts as you need (normally just one). Each should have a unique access token.
85
85
  RollbarApi::Account.configure("my-organization", ENV["ROLLBAR_ACCOUNT_ACCESS_TOKEN"])
@@ -94,6 +94,18 @@ account = RollbarApi::Account.find("my-organization")
94
94
  users = account.get("/api/1/users")
95
95
  ```
96
96
 
97
+ ## Logging
98
+
99
+ You can optionally override the logger with:
100
+
101
+ ```ruby
102
+ # Set it to your own custom logger
103
+ RollbarApi.logger = Rails.logger
104
+
105
+ # Disable logging altogether
106
+ RollbarApi.logger = Logger.new(nil)
107
+ ```
108
+
97
109
  ## Development
98
110
 
99
111
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "rollbar-api"
4
+ require 'bundler/setup'
5
+ require 'rollbar_api'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "rollbar-api"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
data/catalog-info.yaml ADDED
@@ -0,0 +1,12 @@
1
+ ---
2
+ apiVersion: backstage.io/v1alpha1
3
+ kind: Component
4
+ metadata:
5
+ name: rollbar-api
6
+ description: Rollbar API client
7
+ tags:
8
+ - ruby
9
+ - open-source
10
+ spec:
11
+ type: library
12
+ lifecycle: production
@@ -1,14 +1,20 @@
1
- require "dotenv/load"
2
- require "pp"
3
- require "bundler/setup"
4
- require "rollbar-api"
1
+ # frozen_string_literal: true
5
2
 
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"
3
+ require 'dotenv/load'
4
+ require 'bundler/setup'
5
+ require 'rollbar_api'
6
+
7
+ account_name = ENV['ROLLBAR_ACCOUNT_NAME']
8
+ raise 'must specify ROLLBAR_ACCOUNT_NAME in .env' if account_name.blank?
9
+
10
+ account_access_token = ENV['ROLLBAR_ACCOUNT_ACCESS_TOKEN']
11
+ raise 'Must specify ROLLBAR_ACCOUNT_ACCESS_TOKEN in .env' if account_access_token.blank?
12
+
13
+ RollbarApi.logger = Logger.new(nil)
8
14
 
9
15
  account = RollbarApi::Account.configure(account_name, account_access_token)
10
16
 
11
- users = account.get("/api/1/users")
12
- users.result.users.each do |user|
13
- p [user.username, user.email]
17
+ users = account.get('/api/1/users')
18
+ users.result.users.first(5).each do |user|
19
+ p user
14
20
  end
@@ -1,18 +1,22 @@
1
- require "dotenv/load"
2
- require "pp"
3
- require "bundler/setup"
4
- require "rollbar-api"
1
+ # frozen_string_literal: true
5
2
 
6
- project_name = ENV["ROLLBAR_PROJECT_NAME"] or raise "Must specify ROLLBAR_PROJECT_NAME in .env"
7
- project_access_token = ENV["ROLLBAR_PROJECT_ACCESS_TOKEN"] or raise "Must specify ROLLBAR_PROJECT_ACCESS_TOKEN in .env"
3
+ require 'dotenv/load'
4
+ require 'bundler/setup'
5
+ require 'rollbar_api'
6
+
7
+ project_name = ENV['ROLLBAR_PROJECT_NAME']
8
+ project_access_token = ENV['ROLLBAR_PROJECT_ACCESS_TOKEN']
9
+
10
+ raise 'Must specify ROLLBAR_PROJECT_NAME in .env' if project_name.blank?
11
+ raise 'Must specify ROLLBAR_ACCOUNT_ACCESS_TOKEN in .env' if project_access_token.blank?
8
12
 
9
13
  project = RollbarApi::Project.configure(project_name, project_access_token)
10
14
 
11
15
  # Fetch all items
12
- items = project.get("/api/1/items")
16
+ items = project.get('/api/1/items')
13
17
 
14
18
  # Print out the first 5 items
15
19
  items.result.items.first(5).each do |item|
16
- pp item
17
- puts "=" * 80
20
+ p item
21
+ puts '=' * 80
18
22
  end
@@ -1,23 +1,27 @@
1
- require "dotenv/load"
2
- require "pp"
3
- require "bundler/setup"
4
- require "rollbar-api"
1
+ # frozen_string_literal: true
5
2
 
6
- project_name = ENV["ROLLBAR_PROJECT_NAME"] or raise "Must specify ROLLBAR_PROJECT_NAME in .env"
7
- project_access_token = ENV["ROLLBAR_PROJECT_ACCESS_TOKEN"] or raise "Must specify ROLLBAR_PROJECT_ACCESS_TOKEN in .env"
3
+ require 'dotenv/load'
4
+ require 'bundler/setup'
5
+ require 'rollbar_api'
6
+
7
+ project_name = ENV['ROLLBAR_PROJECT_NAME']
8
+ project_access_token = ENV['ROLLBAR_PROJECT_ACCESS_TOKEN']
9
+
10
+ raise 'Must specify ROLLBAR_PROJECT_NAME in .env' if project_name.blank?
11
+ raise 'Must specify ROLLBAR_ACCOUNT_ACCESS_TOKEN in .env' if project_access_token.blank?
8
12
 
9
13
  project = RollbarApi::Project.configure(project_name, project_access_token)
10
14
 
11
15
  # Create the job
12
- rql_job = project.post("/api/1/rql/jobs", {
13
- query_string: "select * from item_occurrence where item.counter=1",
16
+ rql_job = project.post('/api/1/rql/jobs', {
17
+ query_string: 'select * from item_occurrence where item.counter=1',
14
18
  })
15
19
 
16
20
  # Fetch job status
17
21
  rql_job = project.get("/api/1/rql/job/#{rql_job.result.id}")
18
- pp rql_job
22
+ p rql_job
19
23
 
20
- if rql_job.result.status == "success"
24
+ if rql_job.result.status == 'success'
21
25
  # Print out succeeded job result
22
- pp project.get("/api/1/rql/job/#{rql_job.result.id}/result")
26
+ p project.get("/api/1/rql/job/#{rql_job.result.id}/result")
23
27
  end
@@ -1,19 +1,23 @@
1
- require "dotenv/load"
2
- require "pp"
3
- require "bundler/setup"
4
- require "rollbar-api"
1
+ # frozen_string_literal: true
5
2
 
6
- project_name = ENV["ROLLBAR_PROJECT_NAME"] or raise "Must specify ROLLBAR_PROJECT_NAME in .env"
7
- project_access_token = ENV["ROLLBAR_PROJECT_ACCESS_TOKEN"] or raise "Must specify ROLLBAR_PROJECT_ACCESS_TOKEN in .env"
3
+ require 'dotenv/load'
4
+ require 'bundler/setup'
5
+ require 'rollbar_api'
6
+
7
+ project_name = ENV['ROLLBAR_PROJECT_NAME']
8
+ project_access_token = ENV['ROLLBAR_PROJECT_ACCESS_TOKEN']
9
+
10
+ raise 'Must specify ROLLBAR_PROJECT_NAME in .env' if project_PROJECT_NAME.blank?
11
+ raise 'Must specify ROLLBAR_ACCOUNT_ACCESS_TOKEN in .env' if project_access_token.blank?
8
12
 
9
13
  project = RollbarApi::Project.configure(project_name, project_access_token)
10
14
 
11
- top_active_items = project.get("/api/1/reports/top_active_items", {
12
- hours: "24",
13
- environments: "production,staging",
15
+ top_active_items = project.get('/api/1/reports/top_active_items', {
16
+ hours: '24',
17
+ environments: 'production,staging',
14
18
  })
15
19
 
16
- top_active_items.result.each_with_index do |item, i|
17
- pp i, item
18
- puts "=" * 80
20
+ top_active_items.result.first(5).each_with_index do |item, i|
21
+ p i, item
22
+ puts '=' * 80
19
23
  end
data/lib/rollbar-api.rb CHANGED
@@ -1,14 +1,2 @@
1
- require "active_support"
2
- require "active_support/core_ext"
3
- require "faraday"
4
- require "json"
5
- require "recursive-open-struct"
6
-
7
- require "rollbar-api/account"
8
- require "rollbar-api/project"
9
- require "rollbar-api/request"
10
- require "rollbar-api/resource"
11
- require "rollbar-api/version"
12
-
13
- module RollbarApi
14
- end
1
+ # backwards-compatble way to migrate from `require 'rollbar-api'`
2
+ require 'rollbar_api'
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+ require 'active_support/core_ext'
5
+ require 'faraday'
6
+ require 'json'
7
+ require 'recursive-open-struct'
8
+
9
+ require 'rollbar_api/account'
10
+ require 'rollbar_api/logger'
11
+ require 'rollbar_api/project'
12
+ require 'rollbar_api/request'
13
+ require 'rollbar_api/resource'
14
+ require 'rollbar_api/version'
15
+
16
+ module RollbarApi
17
+ end
@@ -1,32 +1,35 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RollbarApi
2
4
  class Account
3
- @@accounts = {}
5
+ @accounts = {}
4
6
 
5
7
  def self.configure(account_name, account_access_token)
6
- @@accounts[account_name] = account_access_token
8
+ @accounts[account_name] = account_access_token
7
9
  find(account_name)
8
10
  end
9
11
 
10
12
  def self.find(account_name)
11
- account_access_token = @@accounts[account_name]
13
+ account_access_token = @accounts[account_name]
12
14
  new(account_name, account_access_token) if account_access_token.present?
13
15
  end
14
16
 
15
17
  def self.all
16
- @@accounts.map { |account_name, _| find(account_name) }
18
+ @accounts.map { |account_name, _| find(account_name) }
17
19
  end
18
20
 
19
21
  def self.delete_all
20
- @@accounts = {}
22
+ @accounts = {}
21
23
  end
22
24
 
23
25
  attr_reader :name, :access_token
26
+
24
27
  def initialize(name, access_token)
25
28
  @name = name
26
29
  @access_token = access_token
27
30
  end
28
31
 
29
- %i(get post put delete head patch).each do |http_method|
32
+ %i[get post put delete head patch].each do |http_method|
30
33
  define_method(http_method) do |path, params = {}|
31
34
  params[:access_token] = access_token
32
35
  response = Request.new(method: http_method, path: path, params: params).execute
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RollbarApi
4
+ @logger = Logger.new($stdout)
5
+ def self.logger=(logger)
6
+ @logger = logger
7
+ end
8
+
9
+ def self.logger
10
+ @logger
11
+ end
12
+ end
@@ -1,32 +1,35 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RollbarApi
2
4
  class Project
3
- @@projects = {}
5
+ @projects = {}
4
6
 
5
7
  def self.configure(project_name, project_access_token)
6
- @@projects[project_name] = project_access_token
8
+ @projects[project_name] = project_access_token
7
9
  find(project_name)
8
10
  end
9
11
 
10
12
  def self.find(project_name)
11
- project_access_token = @@projects[project_name]
13
+ project_access_token = @projects[project_name]
12
14
  new(project_name, project_access_token) if project_access_token.present?
13
15
  end
14
16
 
15
17
  def self.all
16
- @@projects.map { |project_name, _| find(project_name) }
18
+ @projects.map { |project_name, _| find(project_name) }
17
19
  end
18
20
 
19
21
  def self.delete_all
20
- @@projects = {}
22
+ @projects = {}
21
23
  end
22
24
 
23
25
  attr_reader :name, :access_token
26
+
24
27
  def initialize(name, access_token)
25
28
  @name = name
26
29
  @access_token = access_token
27
30
  end
28
31
 
29
- %i(get post put delete head patch).each do |http_method|
32
+ %i[get post put delete head patch].each do |http_method|
30
33
  define_method(http_method) do |path, params = {}|
31
34
  params[:access_token] = access_token
32
35
  response = Request.new(method: http_method, path: path, params: params).execute
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RollbarApi
2
4
  class Request
3
5
  attr_reader :method, :path, :params
6
+
4
7
  def initialize(method:, path:, params:)
5
8
  @method = method
6
- path = "/#{path}" unless path.start_with?("/")
9
+ path = "/#{path}" unless path.start_with?('/')
7
10
  @path = path
8
11
  @params = params
9
12
  end
@@ -16,31 +19,29 @@ module RollbarApi
16
19
  request.url(path)
17
20
  request.body = body_to_json(params) if params.present?
18
21
  end
19
-
22
+
20
23
  request.headers.merge!({
21
- "Accept" => "application/json",
22
- "Content-Type" => "application/json",
24
+ 'Accept' => 'application/json',
25
+ 'Content-Type' => 'application/json',
23
26
  })
24
27
  request
25
28
  end
26
29
  end
27
30
 
28
- private
31
+ private
29
32
 
30
33
  def connection
31
- Faraday.new(url: "https://api.rollbar.com") do |faraday|
32
- faraday.response :logger, ::Logger.new(STDOUT), bodies: false
33
- faraday.adapter Faraday.default_adapter
34
+ Faraday.new(url: 'https://api.rollbar.com') do |faraday|
34
35
  faraday.use Faraday::Response::RaiseError
36
+ faraday.response :logger, RollbarApi.logger, bodies: false
37
+ faraday.adapter Faraday.default_adapter
35
38
  end
36
39
  end
37
40
 
38
41
  def body_to_json(body)
39
- if body
40
- body.is_a?(Array) || body.is_a?(Hash) ? body.to_json : body
41
- else
42
- nil
43
- end
42
+ return if body.blank?
43
+
44
+ body.is_a?(Array) || body.is_a?(Hash) ? body.to_json : body
44
45
  end
45
46
  end
46
47
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RollbarApi
4
+ class Resource
5
+ attr_reader :response_json
6
+
7
+ def initialize(response)
8
+ response = response.body if response.is_a?(Faraday::Response)
9
+ @response_json = if response.is_a?(String)
10
+ JSON.parse(response)
11
+ else
12
+ response
13
+ end
14
+ @struct = ResourceStruct.new(@response_json, { recurse_over_arrays: true })
15
+ end
16
+ delegate :inspect, to: :@struct
17
+
18
+ def as_json(_options = {})
19
+ @response_json
20
+ end
21
+
22
+ def method_missing(name, *args)
23
+ @struct.send(name, *args)
24
+ end
25
+
26
+ def respond_to_missing?(method_name, _include_private = false)
27
+ @struct.respond_to?(method_name)
28
+ end
29
+ end
30
+
31
+ class ResourceStruct < RecursiveOpenStruct
32
+ def inspect
33
+ %(#<RollbarApi::Resource: #{JSON.pretty_generate(@table)}>)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RollbarApi
4
+ VERSION = '0.4.1'
5
+ end
data/rollbar-api.gemspec CHANGED
@@ -1,36 +1,41 @@
1
- # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "rollbar-api/version"
5
+ require 'rollbar_api/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "rollbar-api"
8
+ spec.name = 'rollbar-api'
8
9
  spec.version = RollbarApi::VERSION
9
- spec.authors = ["Peter Graham"]
10
- spec.email = ["peter@wealthsimple.com"]
10
+ spec.authors = ['Peter Graham']
11
+ spec.email = ['peter@wealthsimple.com']
11
12
 
12
- spec.summary = %q{Rubygem for Rollbar REST and RQL APIs}
13
- spec.description = %q{Rubygem for accessing Rollbar's full REST and RQL APIs.}
14
- spec.homepage = "https://github.com/wealthsimple/rollbar-api"
13
+ spec.summary = 'Rubygem for Rollbar REST and RQL APIs'
14
+ spec.description = "Rubygem for accessing Rollbar's full REST and RQL APIs."
15
+ spec.homepage = 'https://github.com/wealthsimple/rollbar-api'
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
18
  f.match(%r{^(test|spec|features)/})
18
19
  end
19
- spec.bindir = "exe"
20
+ spec.bindir = 'exe'
20
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
- spec.require_paths = ["lib"]
22
- spec.license = "MIT"
22
+ spec.require_paths = ['lib']
23
+ spec.license = 'MIT'
24
+
25
+ spec.required_ruby_version = '>= 2.7.3'
23
26
 
24
- spec.add_dependency "activesupport", ">= 4"
25
- spec.add_dependency "faraday", "0.12.1"
26
- spec.add_dependency "recursive-open-struct"
27
+ spec.add_dependency 'activesupport', '>= 4'
28
+ spec.add_dependency 'faraday', '< 1.0'
29
+ spec.add_dependency 'recursive-open-struct'
27
30
 
28
- spec.add_development_dependency "bundler", "~> 1.14"
29
- spec.add_development_dependency "rake", "~> 10.0"
30
- spec.add_development_dependency "rspec", "~> 3.0"
31
- spec.add_development_dependency "rspec-its"
32
- spec.add_development_dependency "rspec-collection_matchers"
33
- spec.add_development_dependency "rspec_junit_formatter", "~> 0.2"
34
- spec.add_development_dependency "webmock", "~> 3.0"
35
- spec.add_development_dependency "dotenv"
31
+ spec.add_development_dependency 'bundler'
32
+ spec.add_development_dependency 'dotenv'
33
+ spec.add_development_dependency 'rake', '~> 10.0'
34
+ spec.add_development_dependency 'rspec', '~> 3.0'
35
+ spec.add_development_dependency 'rspec-collection_matchers'
36
+ spec.add_development_dependency 'rspec-its'
37
+ spec.add_development_dependency 'rspec_junit_formatter', '~> 0.2'
38
+ spec.add_development_dependency 'rubocop'
39
+ spec.add_development_dependency 'webmock', '~> 3.0'
40
+ spec.add_development_dependency 'ws-style'
36
41
  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.2.1
4
+ version: 0.4.1
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-06 00:00:00.000000000 Z
11
+ date: 2021-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.12.1
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '='
38
+ - - "<"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.12.1
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: recursive-open-struct
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -56,16 +56,30 @@ dependencies:
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '1.14'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
- version: '1.14'
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rake
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +109,7 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '3.0'
97
111
  - !ruby/object:Gem::Dependency
98
- name: rspec-its
112
+ name: rspec-collection_matchers
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ">="
@@ -109,7 +123,7 @@ dependencies:
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
- name: rspec-collection_matchers
126
+ name: rspec-its
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - ">="
@@ -136,6 +150,20 @@ dependencies:
136
150
  - - "~>"
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0.2'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
139
167
  - !ruby/object:Gem::Dependency
140
168
  name: webmock
141
169
  requirement: !ruby/object:Gem::Requirement
@@ -151,7 +179,7 @@ dependencies:
151
179
  - !ruby/object:Gem::Version
152
180
  version: '3.0'
153
181
  - !ruby/object:Gem::Dependency
154
- name: dotenv
182
+ name: ws-style
155
183
  requirement: !ruby/object:Gem::Requirement
156
184
  requirements:
157
185
  - - ">="
@@ -171,23 +199,31 @@ executables: []
171
199
  extensions: []
172
200
  extra_rdoc_files: []
173
201
  files:
202
+ - ".github/CODEOWNERS"
203
+ - ".github/workflows/main.yml"
174
204
  - ".gitignore"
175
205
  - ".rspec"
206
+ - ".rubocop.yml"
207
+ - ".ruby-version"
176
208
  - Gemfile
209
+ - Gemfile.lock
177
210
  - README.md
178
211
  - Rakefile
179
212
  - bin/console
180
213
  - bin/setup
214
+ - catalog-info.yaml
181
215
  - examples/list_account_users.rb
182
216
  - examples/list_items.rb
183
217
  - examples/rql_query.rb
184
218
  - examples/top_active_items.rb
185
219
  - lib/rollbar-api.rb
186
- - lib/rollbar-api/account.rb
187
- - lib/rollbar-api/project.rb
188
- - lib/rollbar-api/request.rb
189
- - lib/rollbar-api/resource.rb
190
- - lib/rollbar-api/version.rb
220
+ - lib/rollbar_api.rb
221
+ - lib/rollbar_api/account.rb
222
+ - lib/rollbar_api/logger.rb
223
+ - lib/rollbar_api/project.rb
224
+ - lib/rollbar_api/request.rb
225
+ - lib/rollbar_api/resource.rb
226
+ - lib/rollbar_api/version.rb
191
227
  - rollbar-api.gemspec
192
228
  homepage: https://github.com/wealthsimple/rollbar-api
193
229
  licenses:
@@ -201,15 +237,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
201
237
  requirements:
202
238
  - - ">="
203
239
  - !ruby/object:Gem::Version
204
- version: '0'
240
+ version: 2.7.3
205
241
  required_rubygems_version: !ruby/object:Gem::Requirement
206
242
  requirements:
207
243
  - - ">="
208
244
  - !ruby/object:Gem::Version
209
245
  version: '0'
210
246
  requirements: []
211
- rubyforge_project:
212
- rubygems_version: 2.5.1
247
+ rubygems_version: 3.1.6
213
248
  signing_key:
214
249
  specification_version: 4
215
250
  summary: Rubygem for Rollbar REST and RQL APIs
@@ -1,23 +0,0 @@
1
- module RollbarApi
2
- class Resource
3
- attr_reader :response_json
4
-
5
- def initialize(response)
6
- response = response.body if response.is_a?(Faraday::Response)
7
- @response_json = if response.is_a?(String)
8
- JSON.parse(response)
9
- else
10
- response
11
- end
12
- @struct = RecursiveOpenStruct.new(@response_json, {recurse_over_arrays: true})
13
- end
14
-
15
- def as_json(options = {})
16
- @response_json
17
- end
18
-
19
- def method_missing(name, *args)
20
- @struct.send(name, *args)
21
- end
22
- end
23
- end
@@ -1,3 +0,0 @@
1
- module RollbarApi
2
- VERSION = "0.2.1"
3
- end