giftbit-rails 1.0.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: 598bd714828681e4294bc0f30325973c2be875fda9f7225a47793494b80c7481
4
+ data.tar.gz: f693634c944e63e093f4ecadd8089cc8603cf90c5067e69509751939515a6f12
5
+ SHA512:
6
+ metadata.gz: 891bb572b519ac62ddf15a8d137dcaf027b8125505976ba4077a8e60868e2b06a612a2e848cc298bffdeac71ffe18ff41a62ed024d429570c5c6da412dabcb82
7
+ data.tar.gz: bd187302c2a881c2d94dd72ee9c03d1784e71ae6cc57ba08910cc5e3e14ee7874f31823f26a4423cabde0301296b0f548f456f7fbd62d2d6534f750b1b3cd99b
@@ -0,0 +1,11 @@
1
+ .idea/
2
+ *.gem
3
+ /bin
4
+ /.bundle/
5
+ /.yardoc
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
@@ -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 fakhir.shad@hotmail.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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in giftbit-rails-rails.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Fakhir Shad
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,142 @@
1
+ # giftbit-rails Gem
2
+
3
+ Wrapper for [Giftbit](https://www.giftbit.com/giftbitapi/) API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'giftbit-rails'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install giftbit-rails
20
+
21
+ ## Usage
22
+
23
+ Initialize Giftbit request in your app
24
+
25
+ Giftbit::Request.new(your_api_key, your_api_url)
26
+
27
+ #### Ping
28
+
29
+ response = Giftbit::Ping.ping
30
+
31
+ #### Brand
32
+
33
+ List all Brands
34
+
35
+ response = Giftbit::Brand.all
36
+
37
+ Retrieve Brand
38
+
39
+ response = Giftbit::Brand.show(id: 'brand_code')
40
+
41
+ #### Region
42
+
43
+ List all Regions
44
+
45
+ response = Giftbit::Region.all
46
+
47
+ #### Campaign
48
+
49
+ Create Campaign (params can be found [here](https://www.giftbit.com/giftbitapi/#/reference/1/campaign/create-campaign))
50
+
51
+ response = Giftbit::Campaign.create({
52
+ "gift_template": "XDKHE",
53
+ "contacts": [
54
+ {
55
+ "firstname": "Perry",
56
+ "lastname": "Johnson",
57
+ "email": "pjohnson@giftbit.com"
58
+ },
59
+ {
60
+ "firstname": "Rita",
61
+ "lastname": "Robson",
62
+ "email": "rrobson@giftbit.com"
63
+ }
64
+ ],
65
+ "price_in_cents": 5000,
66
+ "brand_codes": [
67
+ "itunesus",
68
+ "amazonus"
69
+ ],
70
+ "expiry": "2018-11-01",
71
+ "id": "clientProvidedGiftId_abc123"
72
+ })
73
+
74
+ Retrieve Campaign by id or uuid
75
+
76
+ Using id
77
+
78
+ response = Giftbit::Campaign.find(id: 'campaign_id')
79
+
80
+ Using uuid
81
+
82
+ response = Giftbit::Campaign.find(uuid: 'campaign_uuid')
83
+
84
+ #### Funds
85
+
86
+ Retrieve funding information
87
+
88
+ response = Giftbit::Fund.all
89
+
90
+ Add funds through Credit Card (params can be found [here](https://www.giftbit.com/giftbitapi/#/reference/1/funds/add-funds-through-credit-card))
91
+
92
+ response = Giftbit::Fund.create({
93
+ "currencyisocode": "USD",
94
+ "fund_amount_in_cents": 25000,
95
+ "id": "clientProvidedId_abc123"
96
+ })
97
+
98
+ #### Gifts
99
+
100
+ List all Gifts (params can be found [here](https://www.giftbit.com/giftbitapi/#/reference/1/gifts/list-gifts))
101
+
102
+ response = Giftbit::Gift.all
103
+
104
+ Retrieve a particular Gift
105
+
106
+ response = Giftbit::Gift.find(uuid: 'gift_uuid')
107
+
108
+ Resend Gift
109
+
110
+ response = Giftbit::Gift.resend(uuid: 'gift_uuid', resend: true)
111
+
112
+ Cancel Gift
113
+
114
+ response = Giftbit::Gift.cancel(uuid: 'gift_uuid')
115
+
116
+ #### Links
117
+
118
+ Retrieve shortlinks by id or uuid
119
+
120
+ Using id
121
+
122
+ response = Giftbit::Link.find(id: 'link_id')
123
+
124
+ Using uuid
125
+
126
+ response = Giftbit::Link.find(uuid: 'link_uuid')
127
+
128
+ #### Marketplace
129
+
130
+ response = Giftbit::Marktetplace.all
131
+
132
+ ## Contributing
133
+
134
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fakhir-shad/giftbit-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
135
+
136
+ ## License
137
+
138
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
139
+
140
+ ## Code of Conduct
141
+
142
+ Everyone interacting in the giftbit-rails project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fakhir-shad/giftbit-rails/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "giftbit-rails/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "giftbit-rails"
8
+ spec.version = Giftbit::VERSION
9
+ spec.authors = ["Fakhir Shad", "Muaaz Rafi"]
10
+ spec.email = ["fakhir.shad@hotmail.com", "muaazrafi@gmail.com"]
11
+ spec.platform = Gem::Platform::RUBY
12
+
13
+ spec.summary = %q{Giftbit API wrapper}
14
+ spec.description = %q{A simple Ruby wrapper for Giftbit API}
15
+ spec.homepage = "https://github.com/fakhir-shad/giftbit"
16
+ spec.license = "MIT"
17
+
18
+ spec.required_ruby_version = '>= 2.0.0'
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
21
+ f.match(%r{^(test|spec|features)/})
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.16"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_dependency "httparty", "~> 0.13.7"
30
+ end
@@ -0,0 +1,13 @@
1
+ require 'giftbit-rails/marketplace'
2
+ require 'giftbit-rails/link'
3
+ require 'giftbit-rails/gift'
4
+ require 'giftbit-rails/fund'
5
+ require 'giftbit-rails/campaign'
6
+ require 'giftbit-rails/region'
7
+ require 'giftbit-rails/brand'
8
+ require 'giftbit-rails/ping'
9
+ require 'giftbit-rails/request'
10
+ require 'giftbit-rails/error'
11
+
12
+ module Giftbit
13
+ end
@@ -0,0 +1,16 @@
1
+ require 'giftbit-rails/request'
2
+
3
+ module Giftbit
4
+ class Brand < Request
5
+ class << self
6
+ def all *args
7
+ params = extract_params args
8
+ fire_get("/brands", params)
9
+ end
10
+ def find *args
11
+ params = raise_id_error args
12
+ fire_get "/brands/#{params[:id]}", params
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ require 'giftbit-rails/request'
2
+
3
+ module Giftbit
4
+ class Campaign < Request
5
+ class << self
6
+ def create *args
7
+ params = extract_params args
8
+ fire_post("/campaign", params)
9
+ end
10
+ def find *args
11
+ params = raise_id_or_uuid_error args
12
+ id = params[:id] || params[:uuid]
13
+ fire_get "/campaign/#{id}", params
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module Giftbit
2
+ class Error < StandardError; end
3
+ class TimeoutError < StandardError; end
4
+ class UnprocessableEntity < StandardError; end
5
+ class BadRequest < StandardError; end
6
+ class Unauthorized < StandardError; end
7
+ class Forbidden < StandardError; end
8
+ class CreditCardFailure < StandardError; end
9
+ class TooManyRequests < StandardError; end
10
+ class InternalServiceError < StandardError; end
11
+ class ServiceUnavailable < StandardError; end
12
+ end
@@ -0,0 +1,16 @@
1
+ require 'giftbit-rails/request'
2
+
3
+ module Giftbit
4
+ class Fund < Request
5
+ class << self
6
+ def all *args
7
+ params = extract_params args
8
+ fire_get "/funds", params
9
+ end
10
+ def create *args
11
+ params = extract_params args
12
+ fire_post "/funds", params
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ require 'giftbit-rails/request'
2
+
3
+ module Giftbit
4
+ class Gift < Request
5
+ class << self
6
+ def all *args
7
+ params = extract_params args
8
+ fire_get "/gifts", params
9
+ end
10
+ def find *args
11
+ params = raise_uuid_error args
12
+ fire_get "/gifts/#{uuid}", params
13
+ end
14
+ def resend *args
15
+ params = raise_uuid_error args
16
+ (raise argument_error "resend") if params[:resend].blank?
17
+ fire_put "/gifts/#{uuid}", params
18
+ end
19
+ def cancel *args
20
+ raise_uuid_error args
21
+ fire_delete "/gifts/#{uuid}", {}
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ require 'giftbit-rails/request'
2
+
3
+ module Giftbit
4
+ class Link < Request
5
+ def self.find *args
6
+ params = raise_id_or_uuid_error args
7
+ id = params[:id] || params[:uuid]
8
+ fire_get "/links/#{id}", params
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ require 'giftbit-rails/request'
2
+
3
+ module Giftbit
4
+ class Marketplace < Request
5
+ def self.all
6
+ fire_get "/marketplace", {}
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'giftbit-rails/request'
2
+
3
+ module Giftbit
4
+ class Ping < Request
5
+ def self.ping
6
+ fire_get "/ping", {}
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ require 'giftbit-rails/request'
2
+
3
+ module Giftbit
4
+ class Region < Request
5
+ def self.all *args
6
+ params = extract_params args
7
+ fire_get "/regions", params
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,44 @@
1
+ require 'httparty'
2
+ require 'giftbit-rails/util'
3
+
4
+ module Giftbit
5
+ class Request
6
+
7
+ include HTTParty
8
+
9
+ def initialize key, url
10
+ raise self.argument_error("api_key and api_url") if key.blank? || url.blank?
11
+ self.class.base_uri url
12
+ self.class.headers({'Content-Type' => 'application/json', 'Authorization' => "Bearer #{key}"})
13
+ end
14
+
15
+ class << self
16
+ include Util
17
+
18
+ %w(fire_get fire_delete).each do |fire|
19
+ define_method(fire) do |url, args|
20
+ cater_exception fire, url, args, true
21
+ end
22
+ end
23
+
24
+ %w(fire_post fire_put).each do |fire|
25
+ define_method fire do |url, args|
26
+ cater_exception fire, url, args, false
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def cater_exception fire, url, args, query
33
+ begin
34
+ args.reject!{ |arg| arg['id'] || arg['uuid'] }
35
+ params = query ? {query: args} : {body: args.to_json}
36
+ response = send(fire.split('_')[1], url, params)
37
+ extract_errors response
38
+ rescue Net::OpenTimeout, Net::ReadTimeout, Timeout::Error => e
39
+ raise ::Giftbit::TimeoutError.new(e.message)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,43 @@
1
+ module Giftbit
2
+ module Util
3
+ def argument_error(name)
4
+ name ? ArgumentError.new("#{name} is required!") : ArgumentError.new
5
+ end
6
+
7
+ def extract_params(args)
8
+ args.last.is_a?(::Hash) ? args.pop.with_indifferent_access : {}
9
+ end
10
+
11
+ def raise_uuid_error args
12
+ params = extract_params(args)
13
+ argument_error "uuid" if params[:uuid].blank?
14
+ params
15
+ end
16
+
17
+ def raise_id_error args
18
+ params = extract_params(args)
19
+ argument_error "id" if params[:id].blank?
20
+ params
21
+ end
22
+
23
+ def raise_id_or_uuid_error args
24
+ params = extract_params(args)
25
+ id = params[:id] || params[:uuid]
26
+ argument_error "id or uuid" if id.blank?
27
+ params
28
+ end
29
+
30
+ def extract_errors response
31
+ parsed_response = response.parsed_response
32
+ raise Giftbit::BadRequest.new(parsed_response) if response.code == 400
33
+ raise Giftbit::Unauthorized.new(parsed_response) if response.code == 401
34
+ raise Giftbit::CreditCardFailure.new(parsed_response) if response.code == 402
35
+ raise Giftbit::Forbidden.new(parsed_response) if response.code == 403
36
+ raise Giftbit::UnprocessableEntity.new(parsed_response) if response.code == 422
37
+ raise Giftbit::TooManyRequests.new(parsed_response) if response.code == 429
38
+ raise Giftbit::InternalServiceError.new(parsed_response) if response.code == 500
39
+ raise Giftbit::ServiceUnavailable.new(parsed_response) if response.code == 503
40
+ parsed_response
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Giftbit
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: giftbit-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Fakhir Shad
8
+ - Muaaz Rafi
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2018-11-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.16'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.16'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: httparty
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 0.13.7
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 0.13.7
56
+ description: A simple Ruby wrapper for Giftbit API
57
+ email:
58
+ - fakhir.shad@hotmail.com
59
+ - muaazrafi@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - giftbit-rails.gemspec
73
+ - lib/giftbit-rails.rb
74
+ - lib/giftbit-rails/brand.rb
75
+ - lib/giftbit-rails/campaign.rb
76
+ - lib/giftbit-rails/error.rb
77
+ - lib/giftbit-rails/fund.rb
78
+ - lib/giftbit-rails/gift.rb
79
+ - lib/giftbit-rails/link.rb
80
+ - lib/giftbit-rails/marketplace.rb
81
+ - lib/giftbit-rails/ping.rb
82
+ - lib/giftbit-rails/region.rb
83
+ - lib/giftbit-rails/request.rb
84
+ - lib/giftbit-rails/util.rb
85
+ - lib/giftbit-rails/version.rb
86
+ homepage: https://github.com/fakhir-shad/giftbit
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 2.0.0
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.7.3
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Giftbit API wrapper
110
+ test_files: []