moonclerk 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/moonclerk.rb CHANGED
@@ -26,12 +26,21 @@ require "moonclerk/errors/invalid_request_error"
26
26
  module Moonclerk
27
27
  API_BASE = "https://api.moonclerk.com"
28
28
  API_VERSION = 1
29
+ DEFAULT_CA_BUNDLE_PATH = File.join(File.dirname(__FILE__), '/data/ca_certificates.crt')
30
+
31
+ @verify_ssl_certs = true
29
32
 
30
33
  class << self
31
- attr_accessor :api_key
34
+ attr_accessor :api_key, :verify_ssl_certs, :env
32
35
  end
33
36
 
34
37
  def self.request(method, url, params = {})
38
+ unless env
39
+ env = Rails.env
40
+ end
41
+
42
+ env = env.to_sym unless env.is_a?(Symbol)
43
+
35
44
  unless api_key
36
45
  raise AuthenticationError.new('No API key provided. ' \
37
46
  'Set your API key using "Moonclerk.api_key = <API-KEY>". ' \
@@ -45,7 +54,27 @@ module Moonclerk
45
54
  'MoonClerk web interface by logging in at moonclerk.com.)')
46
55
  end
47
56
 
48
- connection = Faraday.new
57
+ if verify_ssl_certs
58
+ ssl_options = {
59
+ ssl: {
60
+ ca_file: Moonclerk::DEFAULT_CA_BUNDLE_PATH
61
+ }
62
+ }
63
+ else
64
+ ssl_options = {
65
+ ssl: {
66
+ verify: false
67
+ }
68
+ }
69
+ unless @verify_ssl_warned
70
+ @verify_ssl_warned = true
71
+ $stderr.puts("WARNING: Running without SSL cert verification. " \
72
+ "You should never do this in production. " \
73
+ "Execute 'Moonclerk.verify_ssl_certs = true' to enable verification.")
74
+ end
75
+ end
76
+
77
+ connection = Faraday.new(ssl_options)
49
78
  response = connection.send(method, url, params, headers)
50
79
  parsed_response = JSON.parse(response.body)
51
80
  symbolized_response = Util.symbolize_names(parsed_response)
@@ -1,3 +1,3 @@
1
1
  module Moonclerk
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moonclerk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trevor Hinesley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-25 00:00:00.000000000 Z
11
+ date: 2015-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -181,6 +181,7 @@ files:
181
181
  - Rakefile
182
182
  - bin/console
183
183
  - bin/setup
184
+ - lib/data/ca_certificates.crt
184
185
  - lib/moonclerk.rb
185
186
  - lib/moonclerk/api_operations/list.rb
186
187
  - lib/moonclerk/api_operations/request.rb