wavecrest 0.0.21 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea8bb3dc2ae121b3c4bcf813ad7c4ae538c90102
4
- data.tar.gz: d1e6a137b617dc96fd62288b3e9e35fbcf943ab7
3
+ metadata.gz: 7dce306297db11071d9baadbfb267f9811b4c2cf
4
+ data.tar.gz: e028b194e1842263c83a13ea6732ff6ed631f5e6
5
5
  SHA512:
6
- metadata.gz: 60a0fa2ba168f14fe692f5566c85b9ec349876f95a2dd8511eece7e24ccd3bae33b848f508b2f046a7d4f71ebd036033becd860e3ee6dea2a68427b7edcb95ac
7
- data.tar.gz: 11d4d1a788d0475b5166568d1e20292415523c9c64e03d15bdcf56cc10e24800411de4ab5d779f530569d09fcb5fb8f003e4bc98ebf5e61f4c964a8c1c91c492
6
+ metadata.gz: c94bca47c04446de00af5ad8cd29c12c2219b58288206e29e7331d41e8ce1757204bff88bce856e263c684bf0b67fc4a1c100db46e70c98ff01242dbc7a25916
7
+ data.tar.gz: d35276bed272521a673665f2daa1108ddcd411a1dea58eea94f1ddd1d3823551be3797bfbc3a33c49f65e48cd21a73db57b59885539c9d8b8b2bd789e1e342c9
data/lib/wavecrest.rb CHANGED
@@ -80,47 +80,76 @@ module Wavecrest
80
80
  end
81
81
 
82
82
  def self.auth
83
- url = configuration.endpoint + "/v3/services/authenticator"
84
-
85
- headers = {
86
- "DeveloperId" => configuration.user,
87
- "DeveloperPassword" => configuration.password,
88
- "X-Method-Override" => 'login',
89
- accept: :json,
90
- content_type: :json
91
- }
83
+ url = URI("#{configuration.endpoint}/v3/services/authenticator")
84
+
85
+ if configuration.proxy
86
+ proxy_uri = URI.parse(configuration.proxy)
87
+ http = Net::HTTP.new(url.host, url.port, proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
88
+ else
89
+ http = Net::HTTP.new(url.host, url.port)
90
+ end
91
+
92
+ if url.scheme == 'https'
93
+ http.use_ssl = true
94
+ end
92
95
 
93
- RestClient.proxy = configuration.proxy if configuration.proxy
94
- request = RestClient::Request.new(method: :post, url: url, headers: headers)
95
- response = request.execute.body
96
- RestClient.proxy = nil
97
- data = JSON.parse response
96
+ request = Net::HTTP::Post.new(url.request_uri)
97
+ request.add_field('Content-Type', 'application/json')
98
+ request.add_field('Accept', 'application/json')
99
+ request.add_field('DeveloperId', configuration.user)
100
+ request.add_field('DeveloperPassword', configuration.password)
101
+ request.add_field('X-Method-Override', 'login')
102
+
103
+ response = http.request(request)
104
+ data = JSON.parse response.body
98
105
  ENV['_WAVECREST_AUTH_TOKEN'] = data["token"]
99
106
  ENV['_WAVECREST_AUTH_TOKEN_ISSUED'] = Time.now.to_i.to_s
100
- # puts "WC Authenticated: #{data["token"]}"
101
107
  end
102
108
 
103
109
 
104
110
  def self.send_request method, path, params={}
105
111
  auth if auth_need?
106
112
 
107
- url = configuration.endpoint + "/v3/services" + path
108
- payload = params.to_json
109
- headers = {
110
- "DeveloperId" => configuration.user,
111
- "DeveloperPassword" => configuration.password,
112
- "AuthenticationToken" => auth_token,
113
- accept: :json,
114
- content_type: :json
115
- }
113
+ # path must begin with slash
114
+ url = URI(configuration.endpoint + "/v3/services" + path)
115
+
116
+ # Build the connection
117
+ if configuration.proxy
118
+ proxy_uri = URI.parse(configuration.proxy)
119
+ http = Net::HTTP.new(url.host, url.port, proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
120
+ else
121
+ http = Net::HTTP.new(url.host, url.port)
122
+ end
123
+
124
+ if url.scheme == 'https'
125
+ http.use_ssl = true
126
+ end
127
+
128
+ if method == :get
129
+ request = Net::HTTP::Get.new(url.request_uri)
130
+ elsif method == :post
131
+ request = Net::HTTP::Post.new(url.request_uri)
132
+ elsif method == :delete
133
+ request = Net::HTTP::Delete.new(url.request_uri)
134
+ elsif method == :put
135
+ request = Net::HTTP::Put.new(url.request_uri)
136
+ else
137
+ raise 'Unsupported request method'
138
+ end
139
+
140
+ unless method == :get
141
+ request.body = params.to_json
142
+ end
143
+
144
+ request.add_field('Content-Type', 'application/json')
145
+ request.add_field('Accept', 'application/json')
146
+ request.add_field('DeveloperId', configuration.user)
147
+ request.add_field('DeveloperPassword', configuration.password)
148
+ request.add_field('AuthenticationToken', auth_token)
116
149
 
117
150
  begin
118
- RestClient.proxy = configuration.proxy if configuration.proxy
119
- # puts "WC request: #{method} #{url}"
120
- request = RestClient::Request.new(method: method, url: url, payload: payload, headers: headers)
121
- response = request.execute.body
122
- RestClient.proxy = nil
123
- JSON.parse response
151
+ response = http.request(request)
152
+ JSON.parse response.body
124
153
  rescue => e
125
154
  # puts e.message, e.response
126
155
  return JSON.parse e.response
@@ -128,6 +157,7 @@ module Wavecrest
128
157
  end
129
158
 
130
159
 
160
+
131
161
  def self.request_card(params)
132
162
  default_params = {
133
163
  "cardProgramId" => "0",
@@ -1,3 +1,3 @@
1
1
  module Wavecrest
2
- VERSION = "0.0.21"
2
+ VERSION = "0.0.22"
3
3
  end
data/wavecrest.gemspec CHANGED
@@ -19,6 +19,5 @@ Gem::Specification.new do |spec|
19
19
  spec.add_development_dependency "bundler", "~> 1.3"
20
20
  spec.add_development_dependency "rake"
21
21
 
22
- spec.add_runtime_dependency 'rest-client'
23
22
  spec.add_runtime_dependency 'json'
24
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wavecrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vadim Marchenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-28 00:00:00.000000000 Z
11
+ date: 2016-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rest-client
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: json
57
43
  requirement: !ruby/object:Gem::Requirement