strike-ruby 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28abee578aa20697a967724cc355e2dede734381
4
- data.tar.gz: 147dae48150828b776a44fca36f12503677d6960
3
+ metadata.gz: a95e9a97a82f02e4eee242b8d568bc6b7f771d30
4
+ data.tar.gz: 56792cd769de9c80d9c30bf309b970d6b107d95d
5
5
  SHA512:
6
- metadata.gz: ca2928bb9e83b7dd4f13b6ca5b2c9aeb8ad9616189b8280961d56cf671f95b3bf91b18ac3e69c821695fb64a4ae72992525df9ae0af538235a12d15c1c97f2cd
7
- data.tar.gz: 0e460a369e21bea2983ec0f57a4cb97e78be10961e986ddd64c734bac687f352b14afdf420b50d39f0088984344d95eee9c40819e2d30f3843e3d93c31171201
6
+ metadata.gz: 37c277f2a51b71de442b39edc911a70a420d34b4e4422ef0cae0d7e5956da8f9ad90391cf2afe3f58ef76d4c5f2d697cda59b2c216acbb267c8ae4654ebb8b42
7
+ data.tar.gz: 9b81f500cb817e69df1d8f06143146b38b23591996537b7d11e6976611b6a739df980b10c1cf3bd62ca618f22cca1bf511d9edb06f590b5f91678618d751aad7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- strike-ruby (0.1.0)
4
+ strike-ruby (0.1.1)
5
5
  faraday
6
6
  json
7
7
 
data/README.md CHANGED
@@ -35,9 +35,6 @@ then use
35
35
 
36
36
  require "strike" # notice this is "strike" not "strike-ruby"
37
37
 
38
- Strike::Client.strike_api_key = "sk_foo"
39
- Strike::Client.strike_api_env = "test"
40
-
41
38
  # List first 30 charges
42
39
  Strike::Charge.all # identical to Strike::Charge.all(page: 1, per_page: 30)
43
40
  # => [#<Strike::Charge:0x00007fb231184300 @id="ch_1jSMVtGiDptw8NQKB6GXTVYA1YJZZ", @amount=42000, @amount_satoshi=42000, @currency="btc", @description="1%20Blockaccino", @customer_id="This is a random test field", @payment_request="lntb520u1pd75atvpp5ntvt72p326r8mhyxeteujsu0p968zu3zfmf6zpvuva8nkr477qaqdqcxyjnyvzzd3hkx6mpvd3kjmn0cqp2qn9cl9hzjjzck6czwrskd0etnq5cjhsjndvlckzvp0hkt02vlhzjxr3raak4jcdkude3v4g8zr4g2ukzkqfjz7n4zvgsqz6qyk7rqxcpa2la7x", @paid=false, @created=1542092140171, @updated=1542092140171, @code=nil, @message=nil>...]
@@ -55,7 +52,7 @@ Strike::Charge.create(amount: 42_000, currency: "btc", description: "The Times 0
55
52
  # => #<Strike::Charge:0x00007fea209216e0 @id="ch_3vymhqec4RZQVfKQtCKH5j3R6yv7u", @amount=42000, @amount_satoshi=42000, @currency="btc", @description="The Times 03/Jan/2009 Chancellor on brink of second bailout for banks", @customer_id="option text for identifying user", @payment_request="lntb420u1pd7hgr4pp5lt8hz548pnutq0z0zcxfsj2j9yu9kn4crzvnhwj5r4228thuzwvsdr0235x2gz5d9kk2ueqxqej7jnpdchnyvps8ysyx6rpde3k2mrvdaezqmmwyp38y6twdvsx7e3qwdjkxmmwvssxyctfd3hh2apqvehhygrzv9hxkuccqp2ev87r57en5smqqjaztv6x6hyddmg8q6e7j4at9prz4w0uz9auymy9ry3jjf7k75h40njgzd7gj5z3rspr9qaq3jhgtyzjfqfep5fracq43wt30", @paid=false, @created=1542168693183, @updated=1542168693183, @code=nil, @message=nil>
56
53
 
57
54
  # Error!
58
- # Strike::Charge.find("foo")
55
+ Strike::Charge.find("foo")
59
56
  # => #<Strike::Charge:0x00007ff7649cd368 @id=nil, @amount=nil, @amount_satoshi=nil, @currency=nil, @description=nil, @customer_id=nil, @payment_request=nil, @paid=nil, @created=nil, @updated=nil, @code=404, @message="not found">
60
57
  ```
61
58
 
@@ -76,7 +73,7 @@ We use [SemVer](http://semver.org/) for versioning.
76
73
 
77
74
  ## Authors
78
75
 
79
- * **Ted Price ** - *Initial work* - [Stacksimple.io](https://github.com/stacksimple)
76
+ * **Ted Price** - *Initial work* - [Stacksimple.io](https://github.com/stacksimple)
80
77
 
81
78
  ## License
82
79
 
@@ -4,4 +4,5 @@ module Strike
4
4
  # Your code goes here...
5
5
  autoload :Client, "strike/client.rb"
6
6
  autoload :Charge, "strike/charge.rb"
7
+ autoload :Errors, "strike/errors.rb"
7
8
  end
@@ -64,6 +64,8 @@ module Strike
64
64
  req.params['page'] = (page - 1).to_i
65
65
  req.params['size'] = per_page.to_i
66
66
  end
67
+ handle_errors(response)
68
+
67
69
  JSON.parse(response.body).map { |attributes| new(attributes) }
68
70
  end
69
71
 
@@ -74,6 +76,8 @@ module Strike
74
76
  # returns [Strike::Charge]
75
77
  def self.find(id)
76
78
  response = conn.get("#{api_url}/#{id}")
79
+ handle_errors(response)
80
+
77
81
  new(JSON.parse(response.body))
78
82
  end
79
83
 
@@ -99,7 +103,15 @@ module Strike
99
103
  req.headers['Content-Type'] = 'application/json'
100
104
  req.body = body.to_json
101
105
  end
106
+
107
+ handle_errors(response)
108
+
102
109
  new(JSON.parse(response.body))
103
110
  end
111
+
112
+ def self.handle_errors(response)
113
+ error = Strike::Errors::ERROR_MAP[response.status]
114
+ raise error.new if error
115
+ end
104
116
  end
105
117
  end
@@ -0,0 +1,47 @@
1
+ module Strike
2
+ class Errors
3
+ BAD_REQUEST = 400
4
+ UNAUTHORIZED = 401
5
+ NOT_FOUND = 404
6
+ TOO_MANY_REQUESTS = 429
7
+ INTERNAL_SERVER_ERROR = 500
8
+
9
+ class BadRequestError < StandardError
10
+ def initialize(msg = 'The request has not been accepted. Check your parameters.')
11
+ super
12
+ end
13
+ end
14
+
15
+ class UnauthorizedError < StandardError
16
+ def initialize(msg = 'Invalid API Key.')
17
+ super
18
+ end
19
+ end
20
+
21
+ class NotFoundError < StandardError
22
+ def initialize(msg = 'The resource does not exist.')
23
+ super
24
+ end
25
+ end
26
+
27
+ class TooManyRequestsError < StandardError
28
+ def initialize(msg = 'You have exceeded your request limit.')
29
+ super
30
+ end
31
+ end
32
+
33
+ class InternalServerError < StandardError
34
+ def initialize(msg = 'There was an internal API error.')
35
+ super
36
+ end
37
+ end
38
+
39
+ ERROR_MAP = {
40
+ BAD_REQUEST => BadRequestError,
41
+ UNAUTHORIZED => UnauthorizedError,
42
+ NOT_FOUND => NotFoundError,
43
+ TOO_MANY_REQUESTS => TooManyRequestsError,
44
+ INTERNAL_SERVER_ERROR => InternalServerError
45
+ }.freeze
46
+ end
47
+ end
@@ -0,0 +1,7 @@
1
+
2
+ 200 The request has succeeded.
3
+ 400 The request has not been accepted. Check your parameters.
4
+ 401 Invalid API Key.
5
+ 404 The resource does not exist.
6
+ 429 You have exceeded your request limit.
7
+ 500 There was an internal API error.
@@ -1,3 +1,3 @@
1
1
  module Strike
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strike-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ted Price
@@ -128,6 +128,8 @@ files:
128
128
  - lib/strike.rb
129
129
  - lib/strike/charge.rb
130
130
  - lib/strike/client.rb
131
+ - lib/strike/errors.rb
132
+ - lib/strike/strike_error.rb
131
133
  - lib/strike/version.rb
132
134
  - strike-ruby.gemspec
133
135
  homepage: https://github.com/stacksimple/strike-ruby