tremendous_ruby 4.3.5 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15fe89c541f3f684e4f5dc44ec917087aaf430381888d7e7d00542d68198bffa
4
- data.tar.gz: a3a835eb8b4d294aa20998f21a69f2aae14324f2de16039e9cb721f3a1e14e20
3
+ metadata.gz: 77f2da41592b55ecf98e0714be4d7f382701079b8f6cddde18b494b02335bb1f
4
+ data.tar.gz: 96a0261f8a02598be0537ee12b6164a7fc0dc750611dcdaa24a5fe40329065cc
5
5
  SHA512:
6
- metadata.gz: ddb556180e0b2a471cd3aa81b7863ea3be8a7786756eb384b0430324ff111fa2449a8f80a5bf05fa58368534d6edd8d418bae7eb04d919d90805b089eeafa356
7
- data.tar.gz: a18c9e1cb65b8e9dafde485733d6bb41f50c93edd749d5ac142f34f76be63eae5fc7622bb61ad80893a8b6ddb39b58d35232f25de96a3324c2d29e23911d9ac2
6
+ metadata.gz: edb99ac73c3ebd9254842bea4e1e07e52ac11b18dc180e2b664637e3228f2f71f9c54a8d49eee88fcef25e2d05c78b24d81acad736ca0de05b7cc3615bd9ce66
7
+ data.tar.gz: 173dc65f26e9e3b2c99da92c01c51542137790cfc33226b0139e2973841566d4dbbea407dd3b7d635cdb8448f83361a9372eaa84ee312697f497af1846f6b81c
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+ require "support/setup"
3
+
4
+ RSpec.describe "Campaigns endpoints" do
5
+ subject(:tremendous_api) { Tremendous::TremendousApi.new }
6
+
7
+ it "list campaigns" do
8
+ campaigns = tremendous_api.list_campaigns.campaigns
9
+
10
+ expect(campaigns.size).to be > 0
11
+
12
+ campaigns.first(10).each do |campaign|
13
+ expect(campaign).to respond_to(:id)
14
+ expect(campaign).to respond_to(:name)
15
+ expect(campaign).to respond_to(:description)
16
+ expect(campaign).to respond_to(:products)
17
+ end
18
+ end
19
+
20
+ it "gets a campaign" do
21
+ campaign = tremendous_api.get_campaign(CAMPAIGN_ID).campaign
22
+
23
+ expect(campaign.id).to eq(CAMPAIGN_ID)
24
+ expect(campaign.products.size).to eq(3)
25
+ expect(campaign.name).to eq("Default Campaign")
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+ require "support/setup"
3
+
4
+ RSpec.describe "Funding Sources endpoints" do
5
+ subject(:tremendous_api) { Tremendous::TremendousApi.new }
6
+
7
+ it "list funding sources" do
8
+ funding_sources = tremendous_api.list_funding_sources.funding_sources
9
+
10
+ expect(funding_sources.size).to be > 0
11
+
12
+ funding_sources.each do |funding_source|
13
+ expect(funding_source).to respond_to(:id)
14
+ expect(funding_source).to respond_to(:method)
15
+ expect(funding_source).to respond_to(:meta)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+ require "support/setup"
3
+
4
+ RSpec.describe "Invoices endpoints" do
5
+ subject(:tremendous_api) { Tremendous::TremendousApi.new }
6
+
7
+ it "list invoices" do
8
+ invoices = tremendous_api.list_invoices.invoices
9
+
10
+ expect(invoices.size).to be > 0
11
+
12
+ invoices.each do |invoice|
13
+ expect(invoice).to respond_to(:id)
14
+ expect(invoice).to respond_to(:po_number)
15
+ expect(invoice).to respond_to(:amount)
16
+ expect(invoice).to respond_to(:created_at)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+ require "support/setup"
3
+
4
+ RSpec.describe "Members endpoints" do
5
+ subject(:tremendous_api) { Tremendous::TremendousApi.new }
6
+
7
+ it "list members" do
8
+ members = tremendous_api.list_members.members
9
+
10
+ expect(members.size).to be > 0
11
+
12
+ members.each do |member|
13
+ expect(member).to respond_to(:id)
14
+ expect(member).to respond_to(:email)
15
+ expect(member).to respond_to(:name)
16
+ expect(member).to respond_to(:role)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,53 @@
1
+ require "spec_helper"
2
+ require "support/setup"
3
+
4
+ RSpec.describe "Orders endpoints" do
5
+ subject(:tremendous_api) { Tremendous::TremendousApi.new }
6
+
7
+ it "list orders" do
8
+ orders = tremendous_api.list_orders.orders
9
+
10
+ expect(orders.size).to be > 0
11
+
12
+ orders.first(10).each do |member|
13
+ expect(member).to respond_to(:id)
14
+ expect(member).to respond_to(:created_at)
15
+ expect(member).to respond_to(:payment)
16
+ end
17
+ end
18
+
19
+ it "submit an order with a campaign" do
20
+ data = tremendous_api.create_order(
21
+ payment: { funding_source_id: "balance" },
22
+ reward: {
23
+ delivery: {
24
+ method: "EMAIL"
25
+ },
26
+ recipient: {
27
+ name: "Recipient Name",
28
+ email: RECIPIENT_EMAIL
29
+ },
30
+ value: {
31
+ denomination: 5.0,
32
+ currency_code: "USD",
33
+ },
34
+ campaign_id: CAMPAIGN_ID,
35
+ })
36
+
37
+ expect(data.order.id).to be
38
+ expect(data.order.campaign_id).to eq(CAMPAIGN_ID)
39
+ expect(data.order.status).to eq("EXECUTED")
40
+ end
41
+
42
+ it "raise validation errors" do
43
+ expect {
44
+ tremendous_api.create_order(payment: { funding_source_id: "WRONG ID"}, reward: {})
45
+ }.to raise_error(Tremendous::ApiError) { |error|
46
+ expect(error.code).to eq(422)
47
+ response = JSON.parse(error.response_body)
48
+
49
+ expect(response["errors"]).to have_key("message")
50
+ expect(response["errors"]).to have_key("payload")
51
+ }
52
+ end
53
+ end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+ require "support/setup"
3
+
4
+ RSpec.describe "Products endpoints" do
5
+ subject(:tremendous_api) { Tremendous::TremendousApi.new }
6
+
7
+ it "list products" do
8
+ products = tremendous_api.list_products.products
9
+
10
+ expect(products.size).to be > 0
11
+
12
+ products.first(10).each do |product|
13
+ expect(product).to respond_to(:id)
14
+ expect(product).to respond_to(:name)
15
+ expect(product).to respond_to(:currency_codes)
16
+ end
17
+ end
18
+
19
+ it "gets a product" do
20
+ product = tremendous_api.get_product(PRODUCT_ID).product
21
+
22
+ expect(product.id).to eq(PRODUCT_ID)
23
+ expect(product).to respond_to(:name)
24
+ expect(product).to respond_to(:currency_codes)
25
+ end
26
+ end
@@ -0,0 +1,111 @@
1
+ =begin
2
+ #API Endpoints
3
+
4
+ #Deliver monetary rewards and incentives to employees, customers, survey participants, and more through the Tremendous API. For organizational tasks, like managing your organization and it's members within Tremendous, please see the Tremendous Organizational API.
5
+
6
+ The version of the OpenAPI document: 2
7
+ Contact: developers@tremendous.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 7.3.0
10
+
11
+ =end
12
+
13
+ # load the gem
14
+ require 'tremendous'
15
+
16
+ # The following was generated by the `rspec --init` command. Conventionally, all
17
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
18
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
19
+ # this file to always be loaded, without a need to explicitly require it in any
20
+ # files.
21
+ #
22
+ # Given that it is always loaded, you are encouraged to keep this file as
23
+ # light-weight as possible. Requiring heavyweight dependencies from this file
24
+ # will add to the boot time of your test suite on EVERY test run, even for an
25
+ # individual file that may not need all of that loaded. Instead, consider making
26
+ # a separate helper file that requires the additional dependencies and performs
27
+ # the additional setup, and require it from the spec files that actually need
28
+ # it.
29
+ #
30
+ # The `.rspec` file also contains a few flags that are not defaults but that
31
+ # users commonly want.
32
+ #
33
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
34
+ RSpec.configure do |config|
35
+ # rspec-expectations config goes here. You can use an alternate
36
+ # assertion/expectation library such as wrong or the stdlib/minitest
37
+ # assertions if you prefer.
38
+ config.expect_with :rspec do |expectations|
39
+ # This option will default to `true` in RSpec 4. It makes the `description`
40
+ # and `failure_message` of custom matchers include text for helper methods
41
+ # defined using `chain`, e.g.:
42
+ # be_bigger_than(2).and_smaller_than(4).description
43
+ # # => "be bigger than 2 and smaller than 4"
44
+ # ...rather than:
45
+ # # => "be bigger than 2"
46
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
47
+ end
48
+
49
+ # rspec-mocks config goes here. You can use an alternate test double
50
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
51
+ config.mock_with :rspec do |mocks|
52
+ # Prevents you from mocking or stubbing a method that does not exist on
53
+ # a real object. This is generally recommended, and will default to
54
+ # `true` in RSpec 4.
55
+ mocks.verify_partial_doubles = true
56
+ end
57
+
58
+ # The settings below are suggested to provide a good initial experience
59
+ # with RSpec, but feel free to customize to your heart's content.
60
+ =begin
61
+ # These two settings work together to allow you to limit a spec run
62
+ # to individual examples or groups you care about by tagging them with
63
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
64
+ # get run.
65
+ config.filter_run :focus
66
+ config.run_all_when_everything_filtered = true
67
+
68
+ # Allows RSpec to persist some state between runs in order to support
69
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
70
+ # you configure your source control system to ignore this file.
71
+ config.example_status_persistence_file_path = "spec/examples.txt"
72
+
73
+ # Limits the available syntax to the non-monkey patched syntax that is
74
+ # recommended. For more details, see:
75
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
76
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
77
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
78
+ config.disable_monkey_patching!
79
+
80
+ # This setting enables warnings. It's recommended, but in some cases may
81
+ # be too noisy due to issues in dependencies.
82
+ config.warnings = true
83
+
84
+ # Many RSpec users commonly either run the entire suite or an individual
85
+ # file, and it's useful to allow more verbose output when running an
86
+ # individual spec file.
87
+ if config.files_to_run.one?
88
+ # Use the documentation formatter for detailed output,
89
+ # unless a formatter has already been configured
90
+ # (e.g. via a command-line flag).
91
+ config.default_formatter = 'doc'
92
+ end
93
+
94
+ # Print the 10 slowest examples and example groups at the
95
+ # end of the spec run, to help surface which specs are running
96
+ # particularly slow.
97
+ config.profile_examples = 10
98
+
99
+ # Run specs in random order to surface order dependencies. If you find an
100
+ # order dependency and want to debug it, you can fix the order by providing
101
+ # the seed, which is printed after each run.
102
+ # --seed 1234
103
+ config.order = :random
104
+
105
+ # Seed global randomization in this process using the `--seed` CLI option.
106
+ # Setting this allows you to use `--seed` to deterministically reproduce
107
+ # test failures related to randomization by passing the same `--seed` value
108
+ # as the one that triggered the failure.
109
+ Kernel.srand config.seed
110
+ =end
111
+ end
@@ -0,0 +1,10 @@
1
+ SANDBOX_TOKEN = ENV.fetch("SANDBOX_API_TOKEN")
2
+ PRODUCT_ID = ENV.fetch("TEST_PRODUCT_ID")
3
+ CAMPAIGN_ID = ENV.fetch("TEST_CAMPAIGN_ID")
4
+ RECIPIENT_EMAIL = ENV.fetch("TEST_RECIPIENT_EMAIL")
5
+
6
+ Tremendous::Configuration.default.configure do |config|
7
+ config.server_index = Tremendous::Configuration::Environment["testflight"]
8
+
9
+ config.access_token = SANDBOX_TOKEN
10
+ end
metadata CHANGED
@@ -1,129 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tremendous_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.5
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tremendous Developers
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-08 00:00:00.000000000 Z
11
+ date: 2024-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activesupport
14
+ name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.2'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
19
+ version: 1.0.1
20
+ - - "<"
25
21
  - !ruby/object:Gem::Version
26
- version: '3.2'
27
- - !ruby/object:Gem::Dependency
28
- name: httparty
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 0.18.0
22
+ version: '3.0'
34
23
  type: :runtime
35
24
  prerelease: false
36
25
  version_requirements: !ruby/object:Gem::Requirement
37
26
  requirements:
38
27
  - - ">="
39
28
  - !ruby/object:Gem::Version
40
- version: 0.18.0
41
- - !ruby/object:Gem::Dependency
42
- name: jwt
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 1.5.0
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
29
+ version: 1.0.1
30
+ - - "<"
53
31
  - !ruby/object:Gem::Version
54
- version: 1.5.0
32
+ version: '3.0'
55
33
  - !ruby/object:Gem::Dependency
56
- name: rake
34
+ name: faraday-multipart
57
35
  requirement: !ruby/object:Gem::Requirement
58
36
  requirements:
59
37
  - - ">="
60
38
  - !ruby/object:Gem::Version
61
- version: 12.3.3
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: 12.3.3
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: 3.5.0
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 3.5.0
83
- - !ruby/object:Gem::Dependency
84
- name: webmock
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '3'
90
- type: :development
39
+ version: '0'
40
+ type: :runtime
91
41
  prerelease: false
92
42
  version_requirements: !ruby/object:Gem::Requirement
93
43
  requirements:
94
44
  - - ">="
95
45
  - !ruby/object:Gem::Version
96
- version: '3'
97
- description:
46
+ version: '0'
47
+ description:
98
48
  email:
99
49
  - developers@tremendous.com
100
50
  executables: []
101
51
  extensions: []
102
52
  extra_rdoc_files: []
103
53
  files:
104
- - lib/tremendous.rb
105
- - lib/tremendous/base.rb
106
- - lib/tremendous/campaign.rb
107
- - lib/tremendous/embed.rb
108
- - lib/tremendous/error.rb
109
- - lib/tremendous/funding_source.rb
110
- - lib/tremendous/invoice.rb
111
- - lib/tremendous/member.rb
112
- - lib/tremendous/order.rb
113
- - lib/tremendous/organization.rb
114
- - lib/tremendous/product.rb
115
- - lib/tremendous/request.rb
116
- - lib/tremendous/rest.rb
117
- - lib/tremendous/reward.rb
118
- - lib/tremendous/version.rb
119
- - lib/tremendous/webhook.rb
54
+ - spec/integration/campaigns_spec.rb
55
+ - spec/integration/funding_sources_spec.rb
56
+ - spec/integration/invoices_spec.rb
57
+ - spec/integration/members_spec.rb
58
+ - spec/integration/orders_spec.rb
59
+ - spec/integration/products_spec.rb
60
+ - spec/spec_helper.rb
61
+ - spec/support/setup.rb
120
62
  homepage: https://github.com/tremendous-rewards/tremendous-ruby
121
63
  licenses:
122
64
  - MIT
123
65
  metadata:
124
66
  documentation_uri: https://www.tremendous.com/docs
125
67
  source_code_uri: https://github.com/tremendous-rewards/tremendous-ruby
126
- post_install_message:
68
+ post_install_message:
127
69
  rdoc_options: []
128
70
  require_paths:
129
71
  - lib
@@ -138,8 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
80
  - !ruby/object:Gem::Version
139
81
  version: '0'
140
82
  requirements: []
141
- rubygems_version: 3.4.10
142
- signing_key:
83
+ rubygems_version: 3.5.3
84
+ signing_key:
143
85
  specification_version: 4
144
86
  summary: Tremendous Ruby API SDK
145
87
  test_files: []
@@ -1,2 +0,0 @@
1
- module Tremendous
2
- end
@@ -1,29 +0,0 @@
1
- module Tremendous
2
- module Campaign
3
-
4
- def self.included(base)
5
- base.include InstanceMethods
6
- end
7
-
8
- module InstanceMethods
9
- def campaigns
10
- CampaignResource.new(access_token, uri)
11
- end
12
- end
13
-
14
- class CampaignResource
15
- include Request
16
-
17
- def list(filters={})
18
- get(
19
- 'campaigns',
20
- query: filters,
21
- )[:campaigns]
22
- end
23
-
24
- def show(id)
25
- get("campaigns/#{id}")[:campaign]
26
- end
27
- end
28
- end
29
- end
@@ -1,13 +0,0 @@
1
- require 'jwt'
2
-
3
- module Tremendous
4
- class Embed
5
- def self.tokenize(access_token, payload)
6
- JWT.encode(
7
- payload,
8
- access_token,
9
- 'HS256'
10
- )
11
- end
12
- end
13
- end
@@ -1,102 +0,0 @@
1
- module Tremendous
2
- class Error < StandardError
3
-
4
- HTTP_STATUS_CODES = {
5
- 100 => 'Continue',
6
- 101 => 'Switching Protocols',
7
- 102 => 'Processing',
8
- 103 => 'Early Hints',
9
- 200 => 'OK',
10
- 201 => 'Created',
11
- 202 => 'Accepted',
12
- 203 => 'Non-Authoritative Information',
13
- 204 => 'No Content',
14
- 205 => 'Reset Content',
15
- 206 => 'Partial Content',
16
- 207 => 'Multi-Status',
17
- 208 => 'Already Reported',
18
- 226 => 'IM Used',
19
- 300 => 'Multiple Choices',
20
- 301 => 'Moved Permanently',
21
- 302 => 'Found',
22
- 303 => 'See Other',
23
- 304 => 'Not Modified',
24
- 305 => 'Use Proxy',
25
- 306 => '(Unused)',
26
- 307 => 'Temporary Redirect',
27
- 308 => 'Permanent Redirect',
28
- 400 => 'Bad Request',
29
- 401 => 'Unauthorized',
30
- 402 => 'Payment Required',
31
- 403 => 'Forbidden',
32
- 404 => 'Not Found',
33
- 405 => 'Method Not Allowed',
34
- 406 => 'Not Acceptable',
35
- 407 => 'Proxy Authentication Required',
36
- 408 => 'Request Timeout',
37
- 409 => 'Conflict',
38
- 410 => 'Gone',
39
- 411 => 'Length Required',
40
- 412 => 'Precondition Failed',
41
- 413 => 'Payload Too Large',
42
- 414 => 'URI Too Long',
43
- 415 => 'Unsupported Media Type',
44
- 416 => 'Range Not Satisfiable',
45
- 417 => 'Expectation Failed',
46
- 421 => 'Misdirected Request',
47
- 422 => 'Unprocessable Entity',
48
- 423 => 'Locked',
49
- 424 => 'Failed Dependency',
50
- 425 => 'Too Early',
51
- 426 => 'Upgrade Required',
52
- 428 => 'Precondition Required',
53
- 429 => 'Too Many Requests',
54
- 431 => 'Request Header Fields Too Large',
55
- 451 => 'Unavailable for Legal Reasons',
56
- 500 => 'Internal Server Error',
57
- 501 => 'Not Implemented',
58
- 502 => 'Bad Gateway',
59
- 503 => 'Service Unavailable',
60
- 504 => 'Gateway Timeout',
61
- 505 => 'HTTP Version Not Supported',
62
- 506 => 'Variant Also Negotiates',
63
- 507 => 'Insufficient Storage',
64
- 508 => 'Loop Detected',
65
- 509 => 'Bandwidth Limit Exceeded',
66
- 510 => 'Not Extended',
67
- 511 => 'Network Authentication Required'
68
- }
69
-
70
- def initialize(response)
71
- @response = response
72
- super
73
- end
74
-
75
- def server_response
76
- @server_response ||= parsed_response
77
- end
78
-
79
- def parsed_response
80
- @response.parsed_response.with_indifferent_access
81
- rescue StandardError
82
- { errors: [ HTTP_STATUS_CODES[@response.code] ] }
83
- end
84
-
85
- def message
86
- "Code: #{@response.code}; Data: #{server_response[:errors]}"
87
- end
88
-
89
- def to_s
90
- message
91
- end
92
- end
93
-
94
- class BadDataError < Error
95
- end
96
-
97
- class PaymentError < Error
98
- end
99
-
100
- class AccessError < Error
101
- end
102
- end
@@ -1,29 +0,0 @@
1
- module Tremendous
2
- module FundingSource
3
-
4
- def self.included(base)
5
- base.include InstanceMethods
6
- end
7
-
8
- module InstanceMethods
9
- def funding_sources
10
- FundingSourceResource.new(access_token, uri)
11
- end
12
- end
13
-
14
- class FundingSourceResource
15
- include Request
16
-
17
- def list(filters={})
18
- get(
19
- 'funding_sources',
20
- query: filters,
21
- )[:funding_sources]
22
- end
23
-
24
- def show(id)
25
- get("funding_sources/#{id}")[:funding_source]
26
- end
27
- end
28
- end
29
- end
@@ -1,44 +0,0 @@
1
- module Tremendous
2
- module Invoice
3
-
4
- def self.included(base)
5
- base.include InstanceMethods
6
- end
7
-
8
- module InstanceMethods
9
- def invoices
10
- InvoiceResource.new(access_token, uri)
11
- end
12
- end
13
-
14
- class InvoiceResource
15
- include Request
16
-
17
- def create!(data={})
18
- post(
19
- 'invoices',
20
- {
21
- body: data.to_json,
22
- headers: { 'Content-Type' => 'application/json' }
23
- }
24
- )[:invoice]
25
- end
26
-
27
- def list(filters={})
28
- get(
29
- 'invoices',
30
- query: filters,
31
- )[:invoices]
32
- end
33
-
34
- def show(id)
35
- get("invoices/#{id}")[:invoice]
36
- end
37
-
38
- def delete!(id)
39
- delete("invoices/#{id}")[:invoice]
40
- end
41
-
42
- end
43
- end
44
- end
@@ -1,37 +0,0 @@
1
- module Tremendous
2
- module Member
3
-
4
- def self.included(base)
5
- base.include InstanceMethods
6
- end
7
-
8
- module InstanceMethods
9
- def members
10
- MemberResource.new(access_token, uri)
11
- end
12
- end
13
-
14
- class MemberResource
15
- include Request
16
-
17
- def create!(data)
18
- post(
19
- "members",
20
- body: data.to_json,
21
- headers: { 'Content-Type' => 'application/json' }
22
- )[:member]
23
- end
24
-
25
- def list(filters={})
26
- get(
27
- "members",
28
- query: filters,
29
- )[:members]
30
- end
31
-
32
- def show(id)
33
- get("members/#{id}")[:member]
34
- end
35
- end
36
- end
37
- end
@@ -1,37 +0,0 @@
1
- module Tremendous
2
- module Order
3
-
4
- def self.included(base)
5
- base.include InstanceMethods
6
- end
7
-
8
- module InstanceMethods
9
- def orders
10
- OrderResource.new(access_token, uri)
11
- end
12
- end
13
-
14
- class OrderResource
15
- include Request
16
-
17
- def create!(data={})
18
- post(
19
- 'orders',
20
- body: data.to_json,
21
- headers: { 'Content-Type' => 'application/json' }
22
- )[:order]
23
- end
24
-
25
- def list(filters={})
26
- get(
27
- 'orders',
28
- query: filters,
29
- )[:orders]
30
- end
31
-
32
- def show(id)
33
- get("orders/#{id}")[:order]
34
- end
35
- end
36
- end
37
- end
@@ -1,38 +0,0 @@
1
- module Tremendous
2
- module Organization
3
-
4
- def self.included(base)
5
- base.include InstanceMethods
6
- end
7
-
8
- module InstanceMethods
9
- def organizations
10
- OrganizationResource.new(access_token, uri)
11
- end
12
- end
13
-
14
- class OrganizationResource
15
- include Request
16
-
17
- def create!(data)
18
- post(
19
- 'organizations',
20
- body: data.to_json,
21
- headers: { 'Content-Type' => 'application/json' }
22
- )[:organization]
23
- end
24
-
25
- def list(filters={})
26
- get('organizations', query: filters)[:organizations]
27
- end
28
-
29
- def create_access_token!(id, data={})
30
- post(
31
- "organizations/#{id}/access_token",
32
- body: data.to_json,
33
- headers: { 'Content-Type' => 'application/json' }
34
- )[:access_token]
35
- end
36
- end
37
- end
38
- end
@@ -1,28 +0,0 @@
1
- module Tremendous
2
- module Product
3
- def self.included(base)
4
- base.include InstanceMethods
5
- end
6
-
7
- module InstanceMethods
8
- def products
9
- ProductResource.new(access_token, uri)
10
- end
11
- end
12
-
13
- class ProductResource
14
- include Request
15
-
16
- def list(filters={})
17
- get(
18
- 'products',
19
- query: filters,
20
- )[:products]
21
- end
22
-
23
- def show(id)
24
- get("products/#{id}")[:product]
25
- end
26
- end
27
- end
28
- end
@@ -1,59 +0,0 @@
1
- module Tremendous
2
- module Request
3
-
4
- def initialize(access_token, uri)
5
- @access_token = access_token
6
- @uri = uri
7
- end
8
-
9
- attr_reader :access_token, :uri
10
-
11
- def get(path, data={}, *opts)
12
- handle_response(_execute(:get, url(path), data, *opts))
13
- end
14
-
15
- def post(path, data={}, *opts)
16
- handle_response(_execute(:post, url(path), data, *opts))
17
- end
18
-
19
- def put(path, data={}, *opts)
20
- handle_response(_execute(:put, url(path), data, *opts))
21
- end
22
-
23
- def delete(path, data={}, *opts)
24
- handle_response(_execute(:delete, url(path), data, *opts))
25
- end
26
-
27
- def _execute(method, url, data={}, *opts)
28
- data[:format] = :json
29
- data[:headers] = {
30
- 'authorization' => "Bearer #{@access_token}",
31
- 'user-agent' => "Tremendous Ruby v#{Tremendous::VERSION}",
32
- 'content-type' => "application/json"
33
- }.merge(data.class == Hash ? data[:headers] || {} : {})
34
-
35
- HTTParty.send(method, url, data, *opts)
36
- end
37
-
38
- def url(path, params={})
39
- URI.join(uri, path)
40
- end
41
-
42
- def handle_response(response)
43
- if response.success?
44
- response_json = JSON.parse(response.body).with_indifferent_access
45
- else
46
- case response.code
47
- when 400
48
- raise Tremendous::BadDataError.new(response)
49
- when 401
50
- raise Tremendous::AccessError.new(response)
51
- when 402
52
- raise Tremendous::PaymentError.new(response)
53
- else
54
- raise Tremendous::Error.new(response)
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,20 +0,0 @@
1
- module Tremendous
2
- class Rest
3
- include Tremendous::Campaign
4
- include Tremendous::FundingSource
5
- include Tremendous::Invoice
6
- include Tremendous::Member
7
- include Tremendous::Order
8
- include Tremendous::Organization
9
- include Tremendous::Product
10
- include Tremendous::Reward
11
- include Tremendous::Webhook
12
-
13
- attr_accessor :access_token, :uri
14
-
15
- def initialize(access_token, uri)
16
- @access_token = access_token
17
- @uri = uri
18
- end
19
- end
20
- end
@@ -1,33 +0,0 @@
1
- module Tremendous
2
- module Reward
3
-
4
- def self.included(base)
5
- base.include InstanceMethods
6
- end
7
-
8
- module InstanceMethods
9
- def rewards
10
- RewardResource.new(access_token, uri)
11
- end
12
- end
13
-
14
- class RewardResource
15
- include Request
16
-
17
- def list(filters={})
18
- get(
19
- 'rewards',
20
- query: filters,
21
- )[:rewards]
22
- end
23
-
24
- def show(id)
25
- get("rewards/#{id}")[:reward]
26
- end
27
-
28
- def generate_link(id)
29
- post("rewards/#{id}/generate_link")[:reward]
30
- end
31
- end
32
- end
33
- end
@@ -1,3 +0,0 @@
1
- module Tremendous
2
- VERSION = '4.3.5'
3
- end
@@ -1,50 +0,0 @@
1
- module Tremendous
2
- module Webhook
3
-
4
- def self.included(base)
5
- base.include InstanceMethods
6
- end
7
-
8
- module InstanceMethods
9
- def webhooks
10
- WebhookResource.new(access_token, uri)
11
- end
12
- end
13
-
14
- class WebhookResource
15
- include Request
16
-
17
- def create!(url, data={})
18
- post(
19
- 'webhooks',
20
- body: {url: url}.merge(data).to_json,
21
- headers: { 'Content-Type' => 'application/json' }
22
- )[:webhook]
23
- end
24
-
25
- def list
26
- get("webhooks")[:webhooks]
27
- end
28
-
29
- def show(id)
30
- get("webhooks/#{id}")[:webhook]
31
- end
32
-
33
- def delete!(id)
34
- delete("webhooks/#{id}")[:webhook]
35
- end
36
-
37
- def events(id)
38
- get("webhooks/#{id}/events")[:events]
39
- end
40
-
41
- def simulate!(id, event, data={})
42
- post(
43
- "webhooks/#{id}/simulate",
44
- body: {event: event}.merge(data).to_json,
45
- headers: { 'Content-Type' => 'application/json' }
46
- )
47
- end
48
- end
49
- end
50
- end
data/lib/tremendous.rb DELETED
@@ -1,18 +0,0 @@
1
- require 'httparty'
2
- require 'active_support/core_ext/hash/indifferent_access'
3
- require 'tremendous/base'
4
- require 'tremendous/version'
5
- require 'tremendous/error'
6
- require 'tremendous/request'
7
- require 'tremendous/campaign'
8
- require 'tremendous/funding_source'
9
- require 'tremendous/invoice'
10
- require 'tremendous/member'
11
- require 'tremendous/order'
12
- require 'tremendous/organization'
13
- require 'tremendous/product'
14
- require 'tremendous/reward'
15
- require 'tremendous/webhook'
16
-
17
- require 'tremendous/rest'
18
- require 'tremendous/embed'