pingpp 2.0.15 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/data/ca-certificates.crt +4030 -89
- data/lib/pingpp/api_operations/create.rb +3 -9
- data/lib/pingpp/api_operations/delete.rb +4 -3
- data/lib/pingpp/api_operations/list.rb +6 -8
- data/lib/pingpp/api_operations/request.rb +46 -0
- data/lib/pingpp/api_operations/update.rb +18 -45
- data/lib/pingpp/api_resource.rb +28 -8
- data/lib/pingpp/batch_refund.rb +14 -0
- data/lib/pingpp/batch_transfer.rb +14 -0
- data/lib/pingpp/charge.rb +3 -4
- data/lib/pingpp/customs.rb +10 -0
- data/lib/pingpp/errors/channel_error.rb +3 -2
- data/lib/pingpp/errors/invalid_request_error.rb +3 -2
- data/lib/pingpp/errors/pingpp_error.rb +4 -1
- data/lib/pingpp/errors/rate_limit_error.rb +4 -0
- data/lib/pingpp/event.rb +1 -3
- data/lib/pingpp/identification.rb +4 -4
- data/lib/pingpp/list_object.rb +12 -12
- data/lib/pingpp/pingpp_object.rb +146 -44
- data/lib/pingpp/red_envelope.rb +7 -3
- data/lib/pingpp/refund.rb +15 -6
- data/lib/pingpp/singleton_api_resource.rb +6 -6
- data/lib/pingpp/transfer.rb +7 -3
- data/lib/pingpp/util.rb +52 -6
- data/lib/pingpp/version.rb +1 -1
- data/lib/pingpp/webhook.rb +3 -3
- data/lib/pingpp/wx_pub_oauth.rb +8 -4
- data/lib/pingpp.rb +178 -67
- metadata +10 -73
@@ -1,15 +1,9 @@
|
|
1
1
|
module Pingpp
|
2
2
|
module APIOperations
|
3
3
|
module Create
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Util.convert_to_pingpp_object(response, api_key)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.included(base)
|
12
|
-
base.extend(ClassMethods)
|
4
|
+
def create(params={}, opts={})
|
5
|
+
response, opts = request(:post, resource_url(opts), params, opts)
|
6
|
+
Util.convert_to_pingpp_object(response, opts)
|
13
7
|
end
|
14
8
|
end
|
15
9
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Pingpp
|
2
2
|
module APIOperations
|
3
3
|
module Delete
|
4
|
-
def delete(params =
|
5
|
-
|
6
|
-
|
4
|
+
def delete(params={}, opts={})
|
5
|
+
opts = Util.normalize_opts(opts)
|
6
|
+
response, opts = request(:delete, resource_url(opts), params, opts)
|
7
|
+
initialize_from(response, opts)
|
7
8
|
end
|
8
9
|
end
|
9
10
|
end
|
@@ -1,16 +1,14 @@
|
|
1
1
|
module Pingpp
|
2
2
|
module APIOperations
|
3
3
|
module List
|
4
|
-
|
5
|
-
|
6
|
-
response, api_key = Pingpp.request(:get, url, api_key, filters)
|
7
|
-
Util.convert_to_pingpp_object(response, api_key)
|
8
|
-
end
|
9
|
-
end
|
4
|
+
def list(filters={}, opts={})
|
5
|
+
opts = Util.normalize_opts(opts)
|
10
6
|
|
11
|
-
|
12
|
-
|
7
|
+
response, opts = request(:get, resource_url(opts), filters, opts)
|
8
|
+
ListObject.construct_from(response, opts)
|
13
9
|
end
|
10
|
+
|
11
|
+
alias :all :list
|
14
12
|
end
|
15
13
|
end
|
16
14
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Pingpp
|
2
|
+
module APIOperations
|
3
|
+
module Request
|
4
|
+
module ClassMethods
|
5
|
+
OPTS_KEYS_TO_PERSIST = Set[:api_key, :api_base, :app, :user]
|
6
|
+
|
7
|
+
def request(method, url, params={}, opts={})
|
8
|
+
opts = Util.normalize_opts(opts)
|
9
|
+
|
10
|
+
headers = opts.clone
|
11
|
+
api_key = headers.delete(:api_key)
|
12
|
+
api_base = headers.delete(:api_base)
|
13
|
+
headers.delete(:app)
|
14
|
+
headers.delete(:user)
|
15
|
+
headers.delete(:parents)
|
16
|
+
# Assume all remaining opts must be headers
|
17
|
+
|
18
|
+
response, opts[:api_key] = Pingpp.request(
|
19
|
+
method, url, api_key, params, headers, api_base
|
20
|
+
)
|
21
|
+
|
22
|
+
# Hash#select returns an array before 1.9
|
23
|
+
opts_to_persist = {}
|
24
|
+
opts.each do |k, v|
|
25
|
+
if OPTS_KEYS_TO_PERSIST.include?(k)
|
26
|
+
opts_to_persist[k] = v
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
[response, opts_to_persist]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.included(base)
|
35
|
+
base.extend(ClassMethods)
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def request(method, url, params={}, opts={})
|
41
|
+
opts = @opts.merge(Util.normalize_opts(opts))
|
42
|
+
self.class.request(method, url, params, opts)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -2,67 +2,40 @@ module Pingpp
|
|
2
2
|
module APIOperations
|
3
3
|
module Update
|
4
4
|
module ClassMethods
|
5
|
-
def update(id, params={},
|
6
|
-
response, opts =
|
5
|
+
def update(id, params={}, opts={})
|
6
|
+
response, opts = request(:put, "#{resource_url(opts)}/#{id}", params, opts)
|
7
7
|
Util.convert_to_pingpp_object(response, opts)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def save(opts={})
|
12
|
-
|
11
|
+
def save(params={}, opts={})
|
12
|
+
update_attributes(params)
|
13
13
|
|
14
|
-
|
15
|
-
values[:metadata] = serialize_metadata
|
16
|
-
end
|
14
|
+
params = params.reject { |k, _| respond_to?(k) }
|
17
15
|
|
18
|
-
|
19
|
-
values.delete(:id)
|
16
|
+
values = self.serialize_params(self).merge(params)
|
20
17
|
|
21
|
-
|
22
|
-
refresh_from(response, api_key)
|
23
|
-
end
|
24
|
-
self
|
25
|
-
end
|
18
|
+
values.delete(:id)
|
26
19
|
|
27
|
-
|
28
|
-
|
29
|
-
# the metadata object has been reassigned
|
30
|
-
# i.e. as object.metadata = {key => val}
|
31
|
-
metadata_update = @values[:metadata] # new hash
|
32
|
-
new_keys = metadata_update.keys.map(&:to_sym)
|
33
|
-
# remove keys at the server, but not known locally
|
34
|
-
keys_to_unset = @previous_metadata.keys - new_keys
|
35
|
-
keys_to_unset.each {|key| metadata_update[key] = ''}
|
20
|
+
response, opts = request(:put, save_url, values, opts)
|
21
|
+
initialize_from(response, opts)
|
36
22
|
|
37
|
-
|
38
|
-
else
|
39
|
-
# metadata is a PingppObject, and can be serialized normally
|
40
|
-
serialize_params(@values[:metadata])
|
41
|
-
end
|
23
|
+
self
|
42
24
|
end
|
43
25
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
''
|
48
|
-
when PingppObject
|
49
|
-
unsaved_keys = obj.instance_variable_get(:@unsaved_values)
|
50
|
-
obj_values = obj.instance_variable_get(:@values)
|
51
|
-
update_hash = {}
|
26
|
+
def self.included(base)
|
27
|
+
base.extend(ClassMethods)
|
28
|
+
end
|
52
29
|
|
53
|
-
|
54
|
-
update_hash[k] = serialize_params(obj_values[k])
|
55
|
-
end
|
30
|
+
private
|
56
31
|
|
57
|
-
|
32
|
+
def save_url
|
33
|
+
if self[:id] == nil && self.class.respond_to?(:create)
|
34
|
+
self.class.resource_url
|
58
35
|
else
|
59
|
-
|
36
|
+
resource_url
|
60
37
|
end
|
61
38
|
end
|
62
|
-
|
63
|
-
def self.included(base)
|
64
|
-
base.extend(ClassMethods)
|
65
|
-
end
|
66
39
|
end
|
67
40
|
end
|
68
41
|
end
|
data/lib/pingpp/api_resource.rb
CHANGED
@@ -1,30 +1,50 @@
|
|
1
1
|
module Pingpp
|
2
2
|
class APIResource < PingppObject
|
3
|
+
include Pingpp::APIOperations::Request
|
4
|
+
|
3
5
|
def self.class_name
|
4
6
|
self.name.split('::')[-1]
|
5
7
|
end
|
6
8
|
|
7
|
-
def self.
|
9
|
+
def self.object_name
|
10
|
+
class_name.downcase
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.uri_object_name
|
14
|
+
object_name
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.resource_url(opts={})
|
8
18
|
if self == APIResource
|
9
19
|
raise NotImplementedError.new('APIResource is an abstract class. You should perform actions on its subclasses (Charge, etc.)')
|
10
20
|
end
|
11
|
-
|
21
|
+
|
22
|
+
if opts.has_key?(:parents)
|
23
|
+
if opts[:parents].is_a?(Array)
|
24
|
+
"/v1/#{opts[:parents].join('/')}/#{CGI.escape(uri_object_name.downcase)}s"
|
25
|
+
else
|
26
|
+
raise ArgumentError.new("opts[:parents] should be an Array")
|
27
|
+
end
|
28
|
+
else
|
29
|
+
"/v1/#{CGI.escape(uri_object_name.downcase)}s"
|
30
|
+
end
|
12
31
|
end
|
13
32
|
|
14
|
-
def
|
33
|
+
def resource_url(opts={})
|
15
34
|
unless id = self['id']
|
16
35
|
raise InvalidRequestError.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{id.inspect}", 'id')
|
17
36
|
end
|
18
|
-
"#{self.class.
|
37
|
+
"#{self.class.resource_url(opts)}/#{CGI.escape(id)}"
|
19
38
|
end
|
20
39
|
|
21
40
|
def refresh
|
22
|
-
response,
|
23
|
-
|
41
|
+
response, opts = request(:get, resource_url(@opts), @retrieve_params)
|
42
|
+
initialize_from(response, opts)
|
24
43
|
end
|
25
44
|
|
26
|
-
def self.retrieve(id,
|
27
|
-
|
45
|
+
def self.retrieve(id, opts={})
|
46
|
+
opts = Util.normalize_opts(opts)
|
47
|
+
instance = self.new(id, opts)
|
28
48
|
instance.refresh
|
29
49
|
instance
|
30
50
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Pingpp
|
2
|
+
class BatchTransfer < APIResource
|
3
|
+
extend Pingpp::APIOperations::Create
|
4
|
+
extend Pingpp::APIOperations::List
|
5
|
+
|
6
|
+
def self.object_name
|
7
|
+
'batch_transfer'
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.resource_url(opts={})
|
11
|
+
'/v1/batch_transfers'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/pingpp/charge.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
module Pingpp
|
2
2
|
class Charge < APIResource
|
3
|
-
|
4
|
-
|
5
|
-
include Pingpp::APIOperations::Update
|
3
|
+
extend Pingpp::APIOperations::Create
|
4
|
+
extend Pingpp::APIOperations::List
|
6
5
|
|
7
6
|
private
|
8
7
|
|
9
8
|
def refund_url
|
10
|
-
|
9
|
+
resource_url + '/refunds'
|
11
10
|
end
|
12
11
|
end
|
13
12
|
end
|
@@ -3,8 +3,9 @@ module Pingpp
|
|
3
3
|
attr_accessor :param
|
4
4
|
attr_accessor :code
|
5
5
|
|
6
|
-
def initialize(message, code, param=nil, http_status=nil, http_body=nil,
|
7
|
-
|
6
|
+
def initialize(message, code, param=nil, http_status=nil, http_body=nil,
|
7
|
+
json_body=nil, http_headers=nil)
|
8
|
+
super(message, http_status, http_body, json_body, http_headers)
|
8
9
|
@code = code
|
9
10
|
@param = param
|
10
11
|
end
|
@@ -2,8 +2,9 @@ module Pingpp
|
|
2
2
|
class InvalidRequestError < PingppError
|
3
3
|
attr_accessor :param
|
4
4
|
|
5
|
-
def initialize(message, param, http_status=nil, http_body=nil, json_body=nil
|
6
|
-
|
5
|
+
def initialize(message, param, http_status=nil, http_body=nil, json_body=nil,
|
6
|
+
http_headers=nil)
|
7
|
+
super(message, http_status, http_body, json_body, http_headers)
|
7
8
|
@param = param
|
8
9
|
end
|
9
10
|
end
|
@@ -4,12 +4,15 @@ module Pingpp
|
|
4
4
|
attr_reader :http_status
|
5
5
|
attr_reader :http_body
|
6
6
|
attr_reader :json_body
|
7
|
+
attr_reader :http_headers
|
7
8
|
|
8
|
-
def initialize(message=nil, http_status=nil, http_body=nil, json_body=nil
|
9
|
+
def initialize(message=nil, http_status=nil, http_body=nil, json_body=nil,
|
10
|
+
http_headers=nil)
|
9
11
|
@message = message
|
10
12
|
@http_status = http_status
|
11
13
|
@http_body = http_body
|
12
14
|
@json_body = json_body
|
15
|
+
@http_headers = http_headers || {}
|
13
16
|
end
|
14
17
|
|
15
18
|
def to_s
|
data/lib/pingpp/event.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Pingpp
|
2
2
|
class Identification < APIResource
|
3
|
-
|
3
|
+
extend Pingpp::APIOperations::Create
|
4
4
|
|
5
|
-
def self.identify(params={},
|
6
|
-
create(params,
|
5
|
+
def self.identify(params={}, opts={})
|
6
|
+
create(params, opts)
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.
|
9
|
+
def self.resource_url(opts={})
|
10
10
|
'/v1/identification'
|
11
11
|
end
|
12
12
|
|
data/lib/pingpp/list_object.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module Pingpp
|
2
2
|
class ListObject < PingppObject
|
3
|
+
include Pingpp::APIOperations::List
|
4
|
+
include Pingpp::APIOperations::Request
|
5
|
+
include Pingpp::APIOperations::Create
|
3
6
|
|
4
7
|
def [](k)
|
5
8
|
case k
|
@@ -14,22 +17,19 @@ module Pingpp
|
|
14
17
|
self.data.each(&blk)
|
15
18
|
end
|
16
19
|
|
17
|
-
def
|
18
|
-
|
19
|
-
response, api_key = Pingpp.request(:get,"#{url}/#{CGI.escape(id)}", api_key)
|
20
|
-
Util.convert_to_pingpp_object(response, api_key)
|
20
|
+
def empty?
|
21
|
+
self.data.empty?
|
21
22
|
end
|
22
23
|
|
23
|
-
def
|
24
|
-
|
25
|
-
response,
|
26
|
-
Util.convert_to_pingpp_object(response,
|
24
|
+
def retrieve(id, opts={})
|
25
|
+
id, retrieve_params = Util.normalize_id(id)
|
26
|
+
response, opts = request(:get, "#{resource_url(opts)}/#{CGI.escape(id)}", retrieve_params, opts)
|
27
|
+
Util.convert_to_pingpp_object(response, opts)
|
27
28
|
end
|
28
29
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
Util.convert_to_pingpp_object(response, api_key)
|
30
|
+
def resource_url(opts={})
|
31
|
+
self.url ||
|
32
|
+
raise(ArgumentError, "List object does not contain a 'url' field.")
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|