authy 2.7.4 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/authy/api.rb CHANGED
@@ -1,21 +1,14 @@
1
- require 'logger'
1
+ require "logger"
2
2
 
3
3
  module Authy
4
-
5
- AUTHY_LOGGER = Logger.new(STDOUT)
6
- #
7
- # Authy.api_key = 'foo'
8
- # Authy.api_uri = 'http://test-authy-api.heroku.com/'
9
- #
10
4
  class API
11
- USER_AGENT = "AuthyRuby/#{Authy::VERSION} (#{RUBY_PLATFORM}, Ruby #{RUBY_VERSION})"
12
5
  MIN_TOKEN_SIZE = 6
13
6
  MAX_TOKEN_SIZE = 12
14
7
 
15
8
  include Authy::URL
16
9
 
17
10
  extend HTTPClient::IncludeClient
18
- include_http_client(agent_name: USER_AGENT)
11
+ include_http_client
19
12
 
20
13
  def self.register_user(attributes)
21
14
  api_key = attributes.delete(:api_key) || Authy.api_key
@@ -26,7 +19,7 @@ module Authy
26
19
  }
27
20
 
28
21
  url = "#{Authy.api_uri}/protected/json/users/new"
29
- response = http_client.post(url, :body => escape_query(params), :header => default_header(api_key: api_key))
22
+ response = http_client.post(url, :body => escape_query(params), :header => default_header(params: { api_key: api_key }))
30
23
 
31
24
  Authy::User.new(response)
32
25
  end
@@ -37,19 +30,18 @@ module Authy
37
30
  # :force (true|false) force to check even if the cellphone is not confirmed
38
31
  #
39
32
  def self.verify(params)
40
- token = params.delete(:token) || params.delete('token')
41
- user_id = params.delete(:id) || params.delete('id')
33
+ token = params.delete(:token) || params.delete("token")
34
+ user_id = params.delete(:id) || params.delete("id")
42
35
 
43
- return invalid_response('Token format is invalid') unless token_is_safe?(token)
44
- return invalid_response('User id is invalid') unless is_digit?(user_id)
36
+ return invalid_response("Token format is invalid") unless token_is_safe?(token)
37
+ return invalid_response("User id is invalid") unless is_digit?(user_id)
45
38
 
46
- params[:force] = true if params[:force].nil? && params['force'].nil?
39
+ params[:force] = true if params[:force].nil? && params["force"].nil?
47
40
 
48
41
  response = get_request("protected/json/verify/:token/:user_id", params.merge({
49
- "token" => token,
50
- "user_id" => user_id
51
- })
52
- )
42
+ "token" => token,
43
+ "user_id" => user_id
44
+ }))
53
45
 
54
46
  return verify_response(response) if response.ok?
55
47
  return response
@@ -59,7 +51,7 @@ module Authy
59
51
  # :id user id
60
52
  # :force force sms
61
53
  def self.request_sms(params)
62
- user_id = params.delete(:id) || params.delete('id')
54
+ user_id = params.delete(:id) || params.delete("id")
63
55
 
64
56
  get_request("protected/json/sms/:user_id", params.merge({"user_id" => user_id}))
65
57
  end
@@ -69,14 +61,14 @@ module Authy
69
61
  # :qr_size qr size
70
62
  # :qr_label context for qr code
71
63
  def self.request_qr_code(params)
72
- user_id = params.delete(:id) || params.delete('id')
73
- qr_size = params.delete(:qr_size) || params.delete('qr_size') || 300
74
- qr_label = params.delete(:qr_label) || params.delete('qr_label') || ""
64
+ user_id = params.delete(:id) || params.delete("id")
65
+ qr_size = params.delete(:qr_size) || params.delete("qr_size") || 300
66
+ qr_label = params.delete(:qr_label) || params.delete("qr_label") || ""
75
67
 
76
- return invalid_response('User id is invalid') unless is_digit?(user_id)
77
- return invalid_response('Qr image size is invalid') unless is_digit?(qr_size)
68
+ return invalid_response("User id is invalid") unless is_digit?(user_id)
69
+ return invalid_response("Qr image size is invalid") unless is_digit?(qr_size)
78
70
 
79
- response = post_request("protected/json/users/:user_id/secret" ,params.merge({
71
+ response = post_request("protected/json/users/:user_id/secret", params.merge({
80
72
  "user_id" => user_id,
81
73
  "qr_size" => qr_size,
82
74
  "label" => qr_label
@@ -87,19 +79,38 @@ module Authy
87
79
  # :id user id
88
80
  # :force force phone_call
89
81
  def self.request_phone_call(params)
90
- user_id = params.delete(:id) || params.delete('id')
82
+ user_id = params.delete(:id) || params.delete("id")
91
83
 
92
84
  get_request("protected/json/call/:user_id", params.merge({"user_id" => user_id}))
93
85
  end
94
86
 
95
87
  # options:
96
88
  # :id user id
97
- def self.delete_user(params)
89
+ def self.request_email(params)
90
+ user_id = params.delete(:id) || params.delete('id')
91
+
92
+ post_request("protected/json/email/:user_id", params.merge({"user_id" => user_id}))
93
+ end
94
+
95
+ # options:
96
+ # :id user id
97
+ # :email user's new email
98
+ def self.update_user(params)
98
99
  user_id = params.delete(:id) || params.delete('id')
99
100
 
100
- post_request("protected/json/users/delete/:user_id", params.merge({"user_id" =>user_id}))
101
+ post_request("protected/json/users/:user_id/update", params.merge({"user_id" => user_id}))
101
102
  end
102
103
 
104
+ # options:
105
+ # :id user id
106
+ def self.delete_user(params)
107
+ user_id = params.delete(:id) || params.delete("id")
108
+
109
+ post_request("protected/json/users/delete/:user_id", params.merge({"user_id" => user_id}))
110
+ end
111
+
112
+ # options:
113
+ # :id user id
103
114
  def self.user_status(params)
104
115
  user_id = params.delete(:id) || params.delete("id")
105
116
  get_request("protected/json/users/:user_id/status", params.merge({"user_id" => user_id}))
@@ -114,12 +125,12 @@ module Authy
114
125
  state, error = validate_for_url(uri_params, params)
115
126
 
116
127
  response = if state
117
- url = "#{Authy.api_uri}/#{eval_uri(uri, params)}"
118
- params = clean_uri_params(uri_params, params)
119
- http_client.post(url, :body => escape_query(params), header: header_)
120
- else
121
- build_error_response(error)
122
- end
128
+ url = "#{Authy.api_uri}/#{eval_uri(uri, params)}"
129
+ params = clean_uri_params(uri_params, params)
130
+ http_client.post(url, :body => escape_query(params), header: header_)
131
+ else
132
+ build_error_response(error)
133
+ end
123
134
  Authy::Response.new(response)
124
135
  end
125
136
 
@@ -129,24 +140,24 @@ module Authy
129
140
  uri_params = keys_to_verify(uri, params)
130
141
  state, error = validate_for_url(uri_params, params)
131
142
  response = if state
132
- url = "#{Authy.api_uri}/#{eval_uri(uri, params)}"
133
- params = clean_uri_params(uri_params, params)
134
- http_client.get(url, params, header_)
135
- else
136
- build_error_response(error)
137
- end
143
+ url = "#{Authy.api_uri}/#{eval_uri(uri, params)}"
144
+ params = clean_uri_params(uri_params, params)
145
+ http_client.get(url, params, header_)
146
+ else
147
+ build_error_response(error)
148
+ end
138
149
  Authy::Response.new(response)
139
150
  end
140
151
 
141
152
  def self.build_error_response(error = "blank uri param found")
142
153
  OpenStruct.new({
143
- 'status' => 400,
144
- 'body' => {
145
- 'success' => false,
146
- 'message' => error,
147
- 'errors' => {
148
- 'message' => error
149
- }
154
+ "status" => 400,
155
+ "body" => {
156
+ "success" => false,
157
+ "message" => error,
158
+ "errors" => {
159
+ "message" => error,
160
+ },
150
161
  }.to_json
151
162
  })
152
163
  end
@@ -159,31 +170,26 @@ module Authy
159
170
  !!(/^\d+$/.match str.to_s)
160
171
  end
161
172
 
162
- def self.invalid_response(str="Invalid resonse")
173
+ def self.invalid_response(str = "Invalid resonse")
163
174
  response = build_error_response(str)
164
175
  return Authy::Response.new(response)
165
176
  end
166
177
 
167
178
  def self.verify_response(response)
168
- return response if response['token'] == 'is valid'
169
- response = build_error_response('Token is invalid')
179
+ return response if response["token"] == "is valid"
180
+ response = build_error_response("Token is invalid")
170
181
  return Authy::Response.new(response)
171
182
  end
172
183
 
173
- def self.default_header(api_key: nil, params: {})
184
+ def self.default_header(params: {})
185
+ api_key = params.delete(:api_key) || params.delete("api_key")
186
+
174
187
  header = {
175
- "X-Authy-API-Key" => api_key || Authy.api_key
188
+ "X-Authy-API-Key" => api_key || Authy.api_key,
189
+ "User-Agent" => Authy.user_agent
176
190
  }
177
191
 
178
- api_key_ = params.delete(:api_key) || params.delete("api_key")
179
-
180
- if api_key_ && api_key_.strip != ""
181
- AUTHY_LOGGER.warn("[DEPRECATED]: The Authy API key should not be sent as a parameter. Please send the HTTP header 'X-Authy-API-Key' instead.")
182
- header["X-Authy-API-Key"] = api_key_
183
- end
184
-
185
192
  return header
186
193
  end
187
-
188
194
  end
189
195
  end
data/lib/authy/config.rb CHANGED
@@ -17,5 +17,13 @@ module Authy
17
17
  @api_uri || "https://api.authy.com"
18
18
  end
19
19
  alias :api_url :api_uri
20
+
21
+ def user_agent
22
+ @user_agent || "AuthyRuby/#{Authy::VERSION} (#{RUBY_PLATFORM}, Ruby #{RUBY_VERSION})"
23
+ end
24
+
25
+ def user_agent=(user_agent)
26
+ @user_agent = user_agent
27
+ end
20
28
  end
21
29
  end
@@ -23,7 +23,7 @@ module Authy
23
23
  begin
24
24
  self.clean_hash!(details)
25
25
  self.clean_hash!(hidden_details)
26
- self.clean_logos!(logos)
26
+ logos = self.clean_logos!(logos)
27
27
  rescue => e
28
28
  return invalid_response("Invalid parameters: #{e.message}")
29
29
  end
@@ -6,8 +6,11 @@ module Authy
6
6
  # :phone_number The persons phone number.
7
7
  # :custom_code Pass along any generated custom code.
8
8
  # :custom_message Custom Message.
9
+ # :code_length Length of code to be sent(4-10).
10
+ # :locale The language of the message received by user.
9
11
  def self.start(params)
10
- params[:via] = "sms" unless %w(sms, call).include?(params[:via])
12
+ warn "Authy Phone Verification has been superseded by the Twilio Verify API. Check https://twil.io/verify-start-ruby to see how to start a verification with the Twilio Verify API."
13
+ params[:via] = "sms" unless %w(sms call).include?(params[:via])
11
14
 
12
15
  post_request("protected/json/phones/verification/start", params)
13
16
  end
@@ -17,8 +20,8 @@ module Authy
17
20
  # :phone_number The persons phone number.
18
21
  # :verification_code The verification code entered by the user.
19
22
  def self.check(params)
23
+ warn "Authy Phone Verification has been superseded by the Twilio Verify API. Check https://twil.io/verify-check-ruby to see how to check a verification the Twilio Verify API."
20
24
  get_request("protected/json/phones/verification/check", params)
21
25
  end
22
-
23
26
  end
24
27
  end
@@ -30,10 +30,6 @@ module Authy
30
30
  [ true, ""]
31
31
  end
32
32
 
33
- def escape_for_url(field)
34
- URI.escape(field.to_s.strip, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
35
- end
36
-
37
33
  def to_param(left, right)
38
34
  HTTP::Message.escape(left) + '=' + HTTP::Message.escape(right.to_s)
39
35
  end
data/lib/authy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Authy
2
- VERSION = "2.7.4"
2
+ VERSION = "3.0.1"
3
3
  end
data/lib/authy.rb CHANGED
@@ -6,11 +6,11 @@ require 'json'
6
6
 
7
7
  require 'authy/version'
8
8
  require 'authy/url_helpers'
9
- require 'authy/core_ext'
10
9
  require 'authy/response'
11
10
  require 'authy/models/user'
12
11
  require 'authy/config'
13
12
  require 'authy/api'
14
- require 'authy/phone_intelligence'
15
13
  require 'authy/phone_verification'
16
14
  require 'authy/onetouch'
15
+
16
+ warn "DEPRECATION WARNING: The authy-ruby library is no longer actively maintained. The Authy API is being replaced by the Twilio Verify API. Please see the README for more details."