gifter_hub 0.1.1 → 0.1.2
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 +4 -4
- data/lib/gifter_hub/api_resource.rb +77 -0
- data/lib/gifter_hub/errors/api_connection_error.rb +6 -0
- data/lib/gifter_hub/errors/api_error.rb +6 -0
- data/lib/gifter_hub/errors/bamboo_error.rb +28 -0
- data/lib/gifter_hub/gift_card.rb +14 -0
- data/lib/gifter_hub/operations/create.rb +9 -0
- data/lib/gifter_hub/operations/{request.rb → get.rb} +1 -1
- data/lib/gifter_hub/version.rb +1 -1
- data/lib/gifter_hub.rb +12 -4
- metadata +9 -4
- data/lib/gifter_hub/gift_cards.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7defb41a5e8993cf87b5267687a41aee0e9dc49
|
4
|
+
data.tar.gz: fa4afb84cfbd7644a8d47c61dc49ec2e73aa630c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 510d7152ffb95850da530658f126bbd14dc4cf1187c802137c02d9dd6966f529a184445840a72c307cbefd6b8c6e337acafdeb044d9b7218bd673dd7c16f8e6c
|
7
|
+
data.tar.gz: 11dcb9cf1a4004febf2d7ebfb437760c5cffc01e2087f20cf6e0d1db2c8b0320e32e88a8eb48293be3b230479fd9da4ba39da8333b4b56d027a3ab46ed588f19
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module GifterHub
|
2
|
+
class ApiResource
|
3
|
+
include Operations::Get
|
4
|
+
attr_accessor :id, :opts
|
5
|
+
|
6
|
+
def initialize(id=nil, opts={})
|
7
|
+
@id = id
|
8
|
+
@opts = opts
|
9
|
+
@values = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.class_name
|
13
|
+
self.name.split('::')[-1]
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.resource_url
|
17
|
+
if self == ApiResource
|
18
|
+
raise NotImplementedError
|
19
|
+
end
|
20
|
+
"/api#{CGI.escape(class_name.tableize)}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.get(id, opts={})
|
24
|
+
instance = self.new(id, opts)
|
25
|
+
instance.refresh
|
26
|
+
end
|
27
|
+
|
28
|
+
def resource_url
|
29
|
+
"#{self.class.resource_url}/#{CGI.escape(id)}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def refresh
|
33
|
+
response = request(:get, resource_url, opts)
|
34
|
+
initialize_from(response, opts)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def self.check_id!(id)
|
40
|
+
raise TypeError.new('id should be a string') unless id.is_a? String
|
41
|
+
id
|
42
|
+
end
|
43
|
+
|
44
|
+
def protected_fields
|
45
|
+
[]
|
46
|
+
end
|
47
|
+
|
48
|
+
# Convert hash key value pair to method
|
49
|
+
def initialize_from(values, opts={})
|
50
|
+
@opts = opts
|
51
|
+
added = Set.new(values.keys - @values.keys)
|
52
|
+
instance_eval do
|
53
|
+
add_accessors(added, values)
|
54
|
+
end
|
55
|
+
self
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_accessors(keys, values)
|
59
|
+
f = protected_fields
|
60
|
+
metaclass.instance_eval do
|
61
|
+
keys.each do |k|
|
62
|
+
next if f.include?(k)
|
63
|
+
define_method(k) { values[k] }
|
64
|
+
|
65
|
+
if [FalseClass, TrueClass].include?(values[k].class)
|
66
|
+
k_bool = :"#{k}?"
|
67
|
+
define_method(k_bool) { values[k] }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def metaclass
|
74
|
+
class << self; self; end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module GifterHub
|
2
|
+
module Errors
|
3
|
+
class BambooError < StandardError
|
4
|
+
attr_reader :message
|
5
|
+
attr_reader :http_status
|
6
|
+
attr_reader :http_body
|
7
|
+
attr_reader :http_headers
|
8
|
+
attr_reader :request_id
|
9
|
+
attr_reader :json_body
|
10
|
+
|
11
|
+
def initialize(message=nil, http_status=nil, http_body=nil, json_body=nil,
|
12
|
+
http_headers=nil)
|
13
|
+
@message = message
|
14
|
+
@http_status = http_status
|
15
|
+
@http_body = http_body
|
16
|
+
@http_headers = http_headers || {}
|
17
|
+
@json_body = json_body
|
18
|
+
@request_id = @http_headers[:request_id]
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
|
23
|
+
id_string = @request_id.nil? ? "" : "(Request #{@request_id}) "
|
24
|
+
"#{status_string}#{id_string}#{@message}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/gifter_hub/version.rb
CHANGED
data/lib/gifter_hub.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
require "rest-client"
|
2
2
|
require "byebug"
|
3
3
|
require 'json'
|
4
|
+
require 'active_support/inflector'
|
4
5
|
|
5
6
|
|
6
7
|
require "gifter_hub/version"
|
7
8
|
require "gifter_hub/util"
|
8
|
-
require "gifter_hub/operations/
|
9
|
-
require "gifter_hub/
|
9
|
+
require "gifter_hub/operations/get"
|
10
|
+
require "gifter_hub/operations/create"
|
11
|
+
|
12
|
+
require "gifter_hub/api_resource"
|
13
|
+
require "gifter_hub/gift_card"
|
10
14
|
|
11
15
|
module GifterHub
|
12
16
|
@api_version = nil
|
13
|
-
@api_base = 'https://gifter.openfan.net
|
17
|
+
@api_base = 'https://gifter.openfan.net'
|
14
18
|
@api_key = nil
|
15
19
|
|
16
20
|
class << self
|
@@ -37,7 +41,10 @@ module GifterHub
|
|
37
41
|
api_base_url = api_base_url || @api_base
|
38
42
|
request_opts = {}
|
39
43
|
url = api_url(url, api_base_url)
|
40
|
-
|
44
|
+
|
45
|
+
headers = {
|
46
|
+
'Access-Token' => company_token
|
47
|
+
}
|
41
48
|
|
42
49
|
case method.to_s.downcase.to_sym
|
43
50
|
when :get, :head, :delete
|
@@ -49,6 +56,7 @@ module GifterHub
|
|
49
56
|
end
|
50
57
|
|
51
58
|
request_opts.update(method: method,
|
59
|
+
headers: headers,
|
52
60
|
payload: payload,
|
53
61
|
url: url)
|
54
62
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gifter_hub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Devhub
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -91,8 +91,13 @@ files:
|
|
91
91
|
- bin/setup
|
92
92
|
- gifter_hub.gemspec
|
93
93
|
- lib/gifter_hub.rb
|
94
|
-
- lib/gifter_hub/
|
95
|
-
- lib/gifter_hub/
|
94
|
+
- lib/gifter_hub/api_resource.rb
|
95
|
+
- lib/gifter_hub/errors/api_connection_error.rb
|
96
|
+
- lib/gifter_hub/errors/api_error.rb
|
97
|
+
- lib/gifter_hub/errors/bamboo_error.rb
|
98
|
+
- lib/gifter_hub/gift_card.rb
|
99
|
+
- lib/gifter_hub/operations/create.rb
|
100
|
+
- lib/gifter_hub/operations/get.rb
|
96
101
|
- lib/gifter_hub/util.rb
|
97
102
|
- lib/gifter_hub/version.rb
|
98
103
|
homepage: https://www.devhub.co/
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module GifterHub
|
2
|
-
class GiftCards
|
3
|
-
|
4
|
-
include Operations::Request
|
5
|
-
|
6
|
-
class << self
|
7
|
-
def purchase(params)
|
8
|
-
url = request_url + 'purchase'
|
9
|
-
request(:post, url, {
|
10
|
-
amount: params[:amount],
|
11
|
-
purchase_price: params[:purchase_price]
|
12
|
-
})
|
13
|
-
end
|
14
|
-
|
15
|
-
def redeem(params)
|
16
|
-
url = request_url + 'redeem'
|
17
|
-
request(:post, url, {
|
18
|
-
amount: params[:amount],
|
19
|
-
id: params[:id]
|
20
|
-
})
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
def request_url
|
25
|
-
'/gift_cards/'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|