sailplay 0.1.3 → 0.2.0
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.
- data/lib/sailplay.rb +9 -5
- data/lib/sailplay/client.rb +24 -9
- data/lib/sailplay/configuration.rb +2 -2
- data/lib/sailplay/rails/client.rb +7 -0
- data/lib/sailplay/version.rb +1 -1
- data/spec/sailplay/client_spec.rb +1 -1
- data/spec/sailplay/configuration_spec.rb +2 -2
- metadata +5 -5
data/lib/sailplay.rb
CHANGED
|
@@ -67,11 +67,11 @@ module Sailplay
|
|
|
67
67
|
# @option options [true|false] :auth — authenticate user
|
|
68
68
|
#
|
|
69
69
|
# @return [Sailplay::User]
|
|
70
|
-
def find_user(
|
|
71
|
-
self.client.find_user(
|
|
70
|
+
def find_user(user_id, options = {})
|
|
71
|
+
self.client.find_user(user_id, options)
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
-
# @param [String
|
|
74
|
+
# @param [String user_id
|
|
75
75
|
# @param [BigDecimal] price
|
|
76
76
|
# @param [Hash] options
|
|
77
77
|
#
|
|
@@ -84,8 +84,12 @@ module Sailplay
|
|
|
84
84
|
# необходимо подтверждать, а про остальные известно что они уже подтверждены.
|
|
85
85
|
#
|
|
86
86
|
# @return [Sailplay::Purchase]
|
|
87
|
-
def create_purchase(
|
|
88
|
-
self.client.create_purchase(
|
|
87
|
+
def create_purchase(user_id, price, options = {})
|
|
88
|
+
self.client.create_purchase(user_id, price, options)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def add_points(user_id, points, comment)
|
|
92
|
+
self.client.add_points(user_id, points, comment)
|
|
89
93
|
end
|
|
90
94
|
|
|
91
95
|
# @param [Integer] order_id
|
data/lib/sailplay/client.rb
CHANGED
|
@@ -43,7 +43,7 @@ module Sailplay
|
|
|
43
43
|
params = {:user_phone => phone}
|
|
44
44
|
params[:extra_fields] = 'auth_hash' if options[:auth]
|
|
45
45
|
|
|
46
|
-
response = request(:get, '/users/reg', :user_phone => phone)
|
|
46
|
+
response = request(:get, '/v1/users/reg', :user_phone => phone)
|
|
47
47
|
if response.success?
|
|
48
48
|
User.parse(response.data)
|
|
49
49
|
else
|
|
@@ -51,17 +51,18 @@ module Sailplay
|
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
# @param [String]
|
|
54
|
+
# @param [String] user_id
|
|
55
55
|
# @param [Hash] options
|
|
56
56
|
#
|
|
57
57
|
# @option options [true|false] :auth — authenticate user
|
|
58
58
|
#
|
|
59
59
|
# @return [Sailplay::User]
|
|
60
|
-
def find_user(
|
|
61
|
-
params = {:
|
|
60
|
+
def find_user(user_id, options = {})
|
|
61
|
+
params = {:origin_user_id => user_id}
|
|
62
|
+
params[:user_phone] = options[:phone] if options[:phone]
|
|
62
63
|
params[:extra_fields] = 'auth_hash' if options[:auth]
|
|
63
64
|
|
|
64
|
-
response =
|
|
65
|
+
response = request(:get, '/v1/users/points-info', params)
|
|
65
66
|
if response.success?
|
|
66
67
|
User.parse(response.data)
|
|
67
68
|
else
|
|
@@ -88,7 +89,7 @@ module Sailplay
|
|
|
88
89
|
|
|
89
90
|
params[:fields] = [:public_key, options[:order_id] && :order_num].compact.join(',')
|
|
90
91
|
|
|
91
|
-
response =
|
|
92
|
+
response = request(:get, '/v1/purchases/new', params)
|
|
92
93
|
|
|
93
94
|
if response.success?
|
|
94
95
|
Purchase.parse(response.data)
|
|
@@ -105,7 +106,7 @@ module Sailplay
|
|
|
105
106
|
params = {:order_num => order_id}
|
|
106
107
|
params[:new_price] = options[:price] if options[:price]
|
|
107
108
|
|
|
108
|
-
response = request(:get, '/purchases/confirm', params)
|
|
109
|
+
response = request(:get, '/v1/purchases/confirm', params)
|
|
109
110
|
|
|
110
111
|
if response.success?
|
|
111
112
|
Purchase.parse(response.data)
|
|
@@ -117,13 +118,27 @@ module Sailplay
|
|
|
117
118
|
# @param [String] gift_public_key
|
|
118
119
|
def confirm_gift(gift_public_key)
|
|
119
120
|
params = {:gift_public_key => gift_public_key}
|
|
120
|
-
response = request(:get, '/ecommerce/gifts/commit-transaction', params)
|
|
121
|
+
response = request(:get, '/v1/ecommerce/gifts/commit-transaction', params)
|
|
121
122
|
|
|
122
123
|
if response.success?
|
|
123
124
|
else
|
|
124
125
|
raise APIError, "Cannot confirm a gift: #{response.error_message}"
|
|
125
126
|
end
|
|
126
127
|
end
|
|
128
|
+
|
|
129
|
+
# @param [String] user_id origin user id
|
|
130
|
+
# @param [Integer] points amount of points to deposit to the user's account
|
|
131
|
+
# @param [String] comment
|
|
132
|
+
def add_points(user_id, points, comment = nil)
|
|
133
|
+
params = {:origin_user_id => user_id, :points => points, :comment => comment}
|
|
134
|
+
response = request(:get, '/v2/points/add', params)
|
|
135
|
+
|
|
136
|
+
if response.success?
|
|
137
|
+
response.data[:public_key]
|
|
138
|
+
else
|
|
139
|
+
raise APIError, "Cannot add points: #{response.error_message}"
|
|
140
|
+
end
|
|
141
|
+
end
|
|
127
142
|
|
|
128
143
|
def request(method, url, params = {})
|
|
129
144
|
execute_request(method, url, auth_params.merge(params))
|
|
@@ -152,7 +167,7 @@ module Sailplay
|
|
|
152
167
|
'please check that store_id, store_key and pin_code are ' +
|
|
153
168
|
'configured' unless credentials?
|
|
154
169
|
|
|
155
|
-
response = execute_request(:get, 'login', credentials)
|
|
170
|
+
response = execute_request(:get, '/v1/login', credentials)
|
|
156
171
|
|
|
157
172
|
if response.success?
|
|
158
173
|
response.data[:token]
|
|
@@ -12,7 +12,7 @@ module Sailplay
|
|
|
12
12
|
# connections, 80 for insecure connections).
|
|
13
13
|
attr_accessor :port
|
|
14
14
|
|
|
15
|
-
# Url prefix for API (defaults to /api
|
|
15
|
+
# Url prefix for API (defaults to /api)
|
|
16
16
|
attr_accessor :endpoint
|
|
17
17
|
|
|
18
18
|
# +true+ for https connections, +false+ for http connections.
|
|
@@ -51,7 +51,7 @@ module Sailplay
|
|
|
51
51
|
def initialize
|
|
52
52
|
@host = 'sailplay.ru'
|
|
53
53
|
@secure = true
|
|
54
|
-
@endpoint = '/api
|
|
54
|
+
@endpoint = '/api'
|
|
55
55
|
|
|
56
56
|
@js_api_path = 'static/js/sailplay.js'
|
|
57
57
|
@js_position = :top_right
|
|
@@ -52,6 +52,13 @@ module Sailplay
|
|
|
52
52
|
rescue Sailplay::Error => e
|
|
53
53
|
logger.error "Error reporting purchase to Sailplay: #{e.message}"
|
|
54
54
|
end
|
|
55
|
+
|
|
56
|
+
def add_sailplay_points(user_id, points, comment)
|
|
57
|
+
key = Sailplay.add_points(user_id, points, comment)
|
|
58
|
+
sailplay_options :public_key => key
|
|
59
|
+
rescue Sailplay::Error => e
|
|
60
|
+
logger.error "Error adding points: #{e.message}"
|
|
61
|
+
end
|
|
55
62
|
|
|
56
63
|
|
|
57
64
|
def sailplay_options(options = {})
|
data/lib/sailplay/version.rb
CHANGED
|
@@ -8,7 +8,7 @@ describe Sailplay::Client do
|
|
|
8
8
|
Sailplay.client.host.should eq('sailplay.ru')
|
|
9
9
|
Sailplay.client.port.should eq(443)
|
|
10
10
|
Sailplay.client.secure.should be_true
|
|
11
|
-
Sailplay.client.endpoint.should eq('/api
|
|
11
|
+
Sailplay.client.endpoint.should eq('/api')
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
it 'should set the options' do
|
|
@@ -18,8 +18,8 @@ describe Sailplay::Configuration do
|
|
|
18
18
|
subject.secure.should be_true
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
it 'should set the endpoint to /api
|
|
22
|
-
subject.endpoint.should eq('/api
|
|
21
|
+
it 'should set the endpoint to /api' do
|
|
22
|
+
subject.endpoint.should eq('/api')
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it 'shouldn\'t set store_id' do
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sailplay
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 23
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
version: 0.
|
|
8
|
+
- 2
|
|
9
|
+
- 0
|
|
10
|
+
version: 0.2.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Sergey Nebolsin
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2013-
|
|
18
|
+
date: 2013-09-05 00:00:00 Z
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
21
21
|
name: multi_json
|