Module: ChipRails
- Defined in:
- lib/chip_rails.rb,
lib/chip_rails.rb,
lib/chip_rails/version.rb
Defined Under Namespace
Classes: Billing, Client, Configuration, Error, PublicKey, Purchase, Webhook
Constant Summary
collapse
- VERSION =
"0.2.0"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
33
34
35
|
# File 'lib/chip_rails.rb', line 33
def configuration
@configuration
end
|
Class Method Details
.config_methods ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/chip_rails.rb', line 42
def config_methods
Configuration.instance_methods(false).each do |attribute|
define_singleton_method(attribute) do
configuration.send(attribute)
end
end
end
|
35
36
37
38
39
40
|
# File 'lib/chip_rails.rb', line 35
def configure
self.configuration ||= Configuration.new
yield(configuration)
configuration.validate!
config_methods
end
|
.make_request(method, path, body: nil) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/chip_rails.rb', line 50
def make_request(method, path, body: nil)
uri = URI(configuration.base_url + path)
case method
when :get
request = Net::HTTP::Get.new(uri, )
when :post
request = Net::HTTP::Post.new(uri, )
request.body = body.to_json
else
raise ArgumentError, "Unsupported HTTP method: #{method}"
end
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
http.request(request)
end
handle_response(response)
end
|
.verify_signature(data, signature, public_key) ⇒ Object
70
71
72
73
74
|
# File 'lib/chip_rails.rb', line 70
def verify_signature(data, signature, public_key)
decoded_signature = Base64.decode64(signature)
rsa_public = OpenSSL::PKey::RSA.new(public_key)
rsa_public.verify(OpenSSL::Digest.new('SHA256'), decoded_signature, data)
end
|