profitwell 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b43f262780dd9b34d65ea5ea562d9af637fe89821dfa4b34f2e129fe11e2d6cf
4
+ data.tar.gz: 59e9099c2f3932ea54a2a10aab4bd8d51a4b70bfcbde79d1a01ee91c536dae39
5
+ SHA512:
6
+ metadata.gz: 385fb0f5b0221c4ef07db19e7d8e3f27911aa4a2cd5a0b63543c21d47dc0c34bbae099975f85fa87b60ec7cb81689cbe3d47878450e4157c87ea26e0dd506b95
7
+ data.tar.gz: 0b153bccfab9732778de79f13f1fa91baea081425817d5b619ce1a2718280cdec70d8b43c7012f899e151d57e4df790b6d3b9914839f78e87dcc835f96063b6a
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5.3
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at eebasadre20@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in profitwell.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,47 @@
1
+ # The Profitwell API Ruby Gem
2
+
3
+ A simple and easy to use Ruby wrapper for ProfitWell's REST API.
4
+
5
+ ProfitWell is the first business intelligence platform to bring together all of your recurring revenue business's financial, usage, and attribution data to one place that's insight laden, absolutely accurate, and 100% free.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'profitwell'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install profitwell
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ Profitwell.config do | config |
27
+ config.access_token = "<access_token_from_profitwell>"
28
+ end
29
+
30
+ ## Development
31
+
32
+ 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.
33
+
34
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/eebasadre20/profitwell-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/eebasadre20/profitwell-ruby/blob/master/CODE_OF_CONDUCT.md).
39
+
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
44
+
45
+ ## Code of Conduct
46
+
47
+ Everyone interacting in the Profitwell project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/eebasadre20/profitwell-ruby/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "profitwell"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ require "httparty"
2
+ require "oj"
3
+ require "profitwell/configuration"
4
+ require "profitwell/exception"
5
+ require "profitwell/common"
6
+ require "profitwell/client"
7
+ require "profitwell/users"
8
+ require "profitwell/version"
9
+
10
+ module Profitwell
11
+ class Error < StandardError; end
12
+
13
+ extend Configuration
14
+
15
+ RESOURCES = %w(users plans subscriptions)
16
+
17
+ class << self
18
+ RESOURCES.each do | resource |
19
+ define_method resource do | resource_id = nil |
20
+ klass_name(resource).new
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def klass_name(resource)
27
+ "Profitwell::#{resource.capitalize}".split("::").inject(Object) { |o, c| o.const_get c }
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,12 @@
1
+ module Profitwell
2
+ module Client
3
+ include Common
4
+
5
+ def api_status
6
+ request(
7
+ "get",
8
+ resource_path("api-status")
9
+ )
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,68 @@
1
+ module Profitwell
2
+ module Common
3
+ include HTTParty
4
+
5
+ ERROR_CODES = {
6
+ 400 => BadRequest,
7
+ 401 => Unauthorized,
8
+ 404 => NotFound,
9
+ 502 => BadGateway,
10
+ }.freeze
11
+
12
+ def resource_path(path = nil, options = "")
13
+ return "#{base_endpoint}/#{path}/?#{options}" if options.nil?
14
+
15
+ "#{base_endpoint}/#{path}/"
16
+ end
17
+
18
+ def request(http_method, endpoint, options: {})
19
+ response = HTTParty.send(http_method, endpoint, params(options).merge!(authorization_header))
20
+ if response.success?
21
+ parse_success response
22
+ else
23
+ parse_failed response
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def params(values)
30
+ {
31
+ body: values.to_json
32
+ }
33
+ end
34
+
35
+ def authorization_header
36
+ @authorization_header ||= {
37
+ headers: {
38
+ 'Content-Type': content_type,
39
+ 'Authorization': access_token
40
+ }
41
+ }
42
+ end
43
+
44
+ def parse_success(response)
45
+ response_hash = response
46
+ end
47
+
48
+ def parse_failed(response)
49
+ error = ERROR_CODES[response.code].new(response)
50
+ raise error, error.message
51
+ end
52
+
53
+ def access_token
54
+ raise 'Access token is missing' unless Profitwell.access_token
55
+ @access_token ||= Profitwell.access_token
56
+ end
57
+
58
+ def content_type
59
+ raise 'Content type is missing' unless Profitwell.content_type
60
+ @content_type ||= Profitwell.content_type
61
+ end
62
+
63
+ def base_endpoint
64
+ raise 'Base API endpoint is missing' unless Profitwell.base_endpoint
65
+ @base_endpoint ||= Profitwell.base_endpoint
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,32 @@
1
+ module Profitwell
2
+ module Configuration
3
+ VALID_OPTIONS_KEYS = [
4
+ :access_token,
5
+ :version,
6
+ :base_endpoint,
7
+ :content_type,
8
+ ].freeze
9
+
10
+ DEFAULT_ACCESS_TOKEN = nil
11
+ DEFAULT_VERSION = "v2".freeze
12
+ DEFAULT_BASE_ENDPOINT = "https://api.profitwell.com/v2".freeze
13
+ DEFAULT_CONTENT_TYPE = "application/json".freeze
14
+
15
+ attr_accessor *VALID_OPTIONS_KEYS
16
+
17
+ def self.extended(base)
18
+ base.reset
19
+ end
20
+
21
+ def config
22
+ yield self if block_given?
23
+ end
24
+
25
+ def reset
26
+ self.access_token = DEFAULT_ACCESS_TOKEN
27
+ self.version = DEFAULT_VERSION
28
+ self.base_endpoint = DEFAULT_BASE_ENDPOINT
29
+ self.content_type = DEFAULT_CONTENT_TYPE
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ module Profitwell
2
+ class Error < StandardError
3
+ attr_reader :message, :type, :code, :error
4
+
5
+ FAILED_HTTP_STATUSES = Array(400..599)
6
+
7
+ def initialize(response)
8
+ # body = JSON.parse(response.body)
9
+
10
+ # @code = "#{response[:status]}"
11
+ # @type = body['meta']['error_type']
12
+ # @message = body['meta']['error_message']
13
+ @code = response.code
14
+ @error = FAILED_HTTP_STATUSES.include? response.code
15
+ @message = response
16
+ end
17
+ end
18
+
19
+ class RuntimeError < Error
20
+ end
21
+
22
+ class BadRequest < Error
23
+ end
24
+
25
+ class NotFound < Error
26
+ end
27
+
28
+ class BadGateway < Error
29
+ end
30
+
31
+ class Unauthorized < Error
32
+ end
33
+ end
@@ -0,0 +1,12 @@
1
+ module Profitwell
2
+ class Users
3
+ include Client
4
+
5
+ def subscriptions(user_alias = nil)
6
+ request(
7
+ "get",
8
+ resource_path("users/#{user_alias}")
9
+ )
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Profitwell
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'lib/profitwell/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "profitwell"
5
+ spec.version = Profitwell::VERSION
6
+ spec.authors = ["eebasadre20"]
7
+ spec.email = ["eebasadre20@gmail.com"]
8
+
9
+ spec.summary = "Profitwell Ruby API Wrapper"
10
+ spec.description = "Profitwell Ruby API Wrapper"
11
+ spec.homepage = "https://github.com/eebasadre20/profitwell"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/eebasadre20/profitwell"
19
+ spec.metadata["changelog_uri"] = "https://github.com/eebasadre20/profitwell/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "httparty"
31
+ spec.add_dependency "oj"
32
+ spec.add_development_dependency "rspec", "~> 3.2"
33
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: profitwell
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - eebasadre20
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ description: Profitwell Ruby API Wrapper
56
+ email:
57
+ - eebasadre20@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/profitwell.rb
72
+ - lib/profitwell/client.rb
73
+ - lib/profitwell/common.rb
74
+ - lib/profitwell/configuration.rb
75
+ - lib/profitwell/exception.rb
76
+ - lib/profitwell/users.rb
77
+ - lib/profitwell/version.rb
78
+ - profitwell.gemspec
79
+ homepage: https://github.com/eebasadre20/profitwell
80
+ licenses:
81
+ - MIT
82
+ metadata:
83
+ allowed_push_host: https://rubygems.org/
84
+ homepage_uri: https://github.com/eebasadre20/profitwell
85
+ source_code_uri: https://github.com/eebasadre20/profitwell
86
+ changelog_uri: https://github.com/eebasadre20/profitwell/CHANGELOG.md
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 2.3.0
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubygems_version: 3.1.2
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Profitwell Ruby API Wrapper
106
+ test_files: []