giftrocket 0.9
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 +7 -0
- data/lib/gift_rocket.rb +40 -0
- data/lib/gift_rocket/account.rb +33 -0
- data/lib/gift_rocket/exceptions.rb +21 -0
- data/lib/gift_rocket/gift.rb +23 -0
- data/lib/gift_rocket/recipient.rb +21 -0
- data/lib/gift_rocket/response.rb +23 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b99f607d117e84704d59d091a26e20e4cdf0ca3a
|
4
|
+
data.tar.gz: 35f39461d411ebd10d2d027b6d34a40d533f2ebe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 40b7e6c3e41ecda62f9b2ad5783739d942f25edcdf4614947de9edb9e7016919f93cf8c82bcd1318ac17ab0cef5159af9c4dc3f7f0c412f4e88fef1e26f83e93
|
7
|
+
data.tar.gz: 711f36f9a97d276f23852d04eb8e7d982479e987648058d29c61c7093969dac6c032501ecf566e26189fdbb17be0bbb852c92702673b5a93d788d493541c7ebf
|
data/lib/gift_rocket.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
class GiftRocket
|
4
|
+
|
5
|
+
def self.quick_send(options)
|
6
|
+
g = GiftRocket::Gift.new(options)
|
7
|
+
a = GiftRocket::Account.new(options)
|
8
|
+
r = GiftRocket::Recipient.new(options)
|
9
|
+
|
10
|
+
send(g,a,r)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.send(gift, account, recipient)
|
14
|
+
options = {
|
15
|
+
:query => merge_params(gift, account, recipient)
|
16
|
+
}
|
17
|
+
|
18
|
+
response = HTTParty.post('https://www.giftrocket.com/gifts', options)
|
19
|
+
|
20
|
+
raise GiftRocket::Error::NetworkError.new(response) unless response.success?
|
21
|
+
|
22
|
+
return GiftRocket::Response.new(response.body)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def self.merge_params(*args)
|
28
|
+
query = {}
|
29
|
+
args.each{|x| query.merge!(x.params)}
|
30
|
+
return query.reject!{|k,v| v.nil?}
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'gift_rocket/account'
|
37
|
+
require 'gift_rocket/response'
|
38
|
+
require 'gift_rocket/gift'
|
39
|
+
require 'gift_rocket/recipient'
|
40
|
+
require 'gift_rocket/exceptions'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class GiftRocket::Account
|
4
|
+
|
5
|
+
@api_key = nil
|
6
|
+
@payment_source = 'card'
|
7
|
+
@sender_name = nil
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
data = File.exists?(self.class.config_file) ? YAML.load_file(self.class.config_file) : {}
|
11
|
+
|
12
|
+
@api_key = options[:api_key] || ENV['GIFT_ROCKET_API_KEY'] || data['api_key']
|
13
|
+
@payment_source = options[:payment_source] || data['payment_source'] || 'card'
|
14
|
+
@sender_name = options[:sender_name] || data['sender_name']
|
15
|
+
|
16
|
+
raise GiftRocket::Error::MissingApiKey.new('api_key not specified') if @api_key.nil?
|
17
|
+
raise GiftRocket::Error::MissingSenderName.new('sender_name not specified') if (@sender_name.nil? || @sender_name.empty?)
|
18
|
+
end
|
19
|
+
|
20
|
+
def send(gift, recipient)
|
21
|
+
GiftRocket.send(gift, self, recipient)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.config_file
|
25
|
+
path = defined?(Rails) ? Rails.root : Dir.getwd
|
26
|
+
File.join(path, 'config/gift_rocket.yml')
|
27
|
+
end
|
28
|
+
|
29
|
+
def params
|
30
|
+
{'api_key' => @api_key, 'payment_source' => @payment_source, 'gift[sender_name]' => @sender_name}
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module GiftRocket::Error
|
2
|
+
|
3
|
+
class MissingApiKey < ArgumentError
|
4
|
+
end
|
5
|
+
|
6
|
+
class InvalidAmount < ArgumentError
|
7
|
+
end
|
8
|
+
|
9
|
+
class MissingRecipientEmail < ArgumentError
|
10
|
+
end
|
11
|
+
|
12
|
+
class MissingRecipientName < ArgumentError
|
13
|
+
end
|
14
|
+
|
15
|
+
class MissingSenderName < ArgumentError
|
16
|
+
end
|
17
|
+
|
18
|
+
class NetworkError < IOError
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class GiftRocket::Gift
|
2
|
+
|
3
|
+
attr_accessor :amount, :message_announce, :yelp_business_id, :test_gift
|
4
|
+
|
5
|
+
@amount = nil
|
6
|
+
@message_announce = nil
|
7
|
+
@yelp_business_id = nil
|
8
|
+
@test_gift = false
|
9
|
+
|
10
|
+
def initialize(options)
|
11
|
+
@amount = options[:amount]
|
12
|
+
@message_announce = options[:message_announce]
|
13
|
+
@yelp_business_id = options[:yelp_business_id]
|
14
|
+
@test_gift = options[:test_gift]
|
15
|
+
|
16
|
+
raise GiftRocket::Error::InvalidAmount.new('Gift Amount not specified') unless (@amount||0) > 0
|
17
|
+
end
|
18
|
+
|
19
|
+
def params
|
20
|
+
{'gift[amount]' => @amount, 'gift[message_announce]' => @message_announce, 'gift[yelp_business_id]' => @yelp_business_id, 'test_gift' => @test_gift}
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class GiftRocket::Recipient
|
2
|
+
|
3
|
+
attr_accessor :email, :name
|
4
|
+
|
5
|
+
@email = nil
|
6
|
+
@name = nil
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
@name = options[:name]
|
10
|
+
@email = options[:email]
|
11
|
+
|
12
|
+
raise GiftRocket::Error::MissingRecipientEmail.new('Recipient email not specified') if @email.nil? || @email.empty?
|
13
|
+
raise GiftRocket::Error::MissingRecipientName.new('Recipient name not specified') if @name.nil? || @name.empty?
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def params
|
18
|
+
{'gift[recipient_email]' => @email, 'gift[recipient_name]' => @name}
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
class GiftRocket::Response
|
4
|
+
|
5
|
+
@data = {}
|
6
|
+
|
7
|
+
def initialize(json_string)
|
8
|
+
@data = JSON.parse(json_string)
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(method_name)
|
12
|
+
@data.has_key?(method_name.to_s) ? @data[method_name.to_s] : super
|
13
|
+
end
|
14
|
+
|
15
|
+
def success?
|
16
|
+
@data['success']
|
17
|
+
end
|
18
|
+
|
19
|
+
def gift_url
|
20
|
+
"https://www.giftrocket.com/gift/#{token}"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: giftrocket
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.9'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alessio Signorini
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-11 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.13'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: webmock
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.22'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.22'
|
41
|
+
description: Simple Library to interact with GiftRocket's API
|
42
|
+
email: alessio@signorini.us
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/gift_rocket.rb
|
48
|
+
- lib/gift_rocket/account.rb
|
49
|
+
- lib/gift_rocket/exceptions.rb
|
50
|
+
- lib/gift_rocket/gift.rb
|
51
|
+
- lib/gift_rocket/recipient.rb
|
52
|
+
- lib/gift_rocket/response.rb
|
53
|
+
homepage: https://github.com/alessio-signorini/giftrocket-ruby
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 2.4.8
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: GiftRocket Client
|
77
|
+
test_files: []
|