phraseapp-ruby 1.0.12 → 1.0.13

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: ff3bfc20f86a49299d53807057419ef85a2f9923
4
- data.tar.gz: bcd653c3577a1f233fbcbf6267a2662a202b0021
3
+ metadata.gz: 3039ead9df5cb430b9e3724285138a4bcdd624da
4
+ data.tar.gz: 6ed573a0c34f80284767bd48e8538d2ef46fd7db
5
5
  SHA512:
6
- metadata.gz: f9541826d360b1217f8b68ab594f8d94424915e8c9bd894282acb8a17754db4cf2b8bee53069aa694ca277daa72e772761a8bff9595132f3059931c080b306d8
7
- data.tar.gz: 9d89382439d84a6d264c7c9fcd1a9e0004c017ae4943096b246a96478c7ab619040a7130c3c9d7a31ec3a8d0bbac72b55cd59c30dcf48c6278c23cbc4119ad2b
6
+ metadata.gz: 247c94438e6033536ff3ce5fa2fca0c8612351949d79936ae6520cf132ad715a848b7bcb9a7796048cd085c49ebd78e0f03be8c9e628bae1f1521f94e559d94c
7
+ data.tar.gz: 0015673bb21c0ecc18be90aec3b8b1422dc2ff312289b8bdc3e76ea1e4491d374b28a786162ac75681cfc6fc3c1eae3a7416e499e5044d175de26098f995b44d
data/lib/auth.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  module PhraseApp
2
+
3
+ URL = "https://api.phraseapp.com"
4
+
2
5
  module Auth
3
6
 
4
7
  class AuthHandler < OpenStruct
@@ -33,6 +36,10 @@ module PhraseApp
33
36
  self.tfa = tmpA.tfa
34
37
  end
35
38
 
39
+ if tmpA.host && self.username.nil?
40
+ self.host = tmpA.host
41
+ end
42
+
36
43
  return nil
37
44
  end
38
45
  end
@@ -44,7 +51,15 @@ module PhraseApp
44
51
  def self.register_auth_handler(a)
45
52
  @@authH = a
46
53
  end
47
-
54
+
55
+ def self.host
56
+ if authH.host && authH.host != ""
57
+ return authH.host
58
+ else
59
+ return PhraseApp::URL
60
+ end
61
+ end
62
+
48
63
  def self.authenticate(req)
49
64
  if authH == nil
50
65
  raise("no auth handler registered")
@@ -981,7 +981,6 @@ end
981
981
 
982
982
  module PhraseApp
983
983
  MULTIPART_BOUNDARY = "{PHRASE!!EOF}"
984
- URL = "https://api.phraseapp.com"
985
984
 
986
985
  module ParamsHelpers
987
986
  class ParamsValidationError < StandardError; end
@@ -1528,7 +1527,7 @@ end
1528
1527
  #
1529
1528
  # Require the gem
1530
1529
  # require 'phraseapp-ruby'
1531
- # Setup Authentication
1530
+ # Setup Authentication
1532
1531
  # auth_handler = PhraseApp::Auth::AuthHandler.new({:token => "YOUR_ACCESS_TOKEN"})
1533
1532
  # PhraseApp::Auth.register_auth_handler(auth_handler)
1534
1533
  # Create a client
@@ -3769,9 +3768,3 @@ end
3769
3768
  end
3770
3769
 
3771
3770
  end
3772
-
3773
-
3774
-
3775
-
3776
-
3777
-
@@ -40,7 +40,7 @@ module PhraseApp
40
40
 
41
41
  class RateLimitingError
42
42
  attr_accessor :limit, :remaining, :reset
43
-
43
+
44
44
  def initialize(resp)
45
45
  re = RateLimitingError.new(resp)
46
46
  puts resp.body.inspect
@@ -49,7 +49,7 @@ module PhraseApp
49
49
  re.reset = Time.at(resp["X-Rate-Limit-Reset"].to_i)
50
50
  return re, nil
51
51
  end
52
-
52
+
53
53
  def to_s
54
54
  sprintf("Rate limit exceeded: from %d requests %d are remaning (reset in %d seconds)", self.limit, self.remaining, int64(rle.Reset.Sub(time.Now()).Seconds()))
55
55
  end
@@ -73,7 +73,7 @@ module PhraseApp
73
73
  hash = if uri.query then CGI::parse(uri.query) else {} end
74
74
  hash["page"] = page
75
75
  hash["per_page"] = per_page
76
-
76
+
77
77
  query_str = URI.encode_www_form(hash)
78
78
  path = [uri.path, query_str].compact.join('?')
79
79
 
@@ -81,9 +81,9 @@ module PhraseApp
81
81
  end
82
82
 
83
83
  def self.send_request(method, path, ctype, data, status)
84
- req = Net::HTTPGenericRequest.new(method,
85
- Module.const_get("Net::HTTP::#{method.capitalize}::REQUEST_HAS_BODY"),
86
- Module.const_get("Net::HTTP::#{method.capitalize}::RESPONSE_HAS_BODY"),
84
+ req = Net::HTTPGenericRequest.new(method,
85
+ Module.const_get("Net::HTTP::#{method.capitalize}::REQUEST_HAS_BODY"),
86
+ Module.const_get("Net::HTTP::#{method.capitalize}::RESPONSE_HAS_BODY"),
87
87
  path)
88
88
 
89
89
 
@@ -98,7 +98,7 @@ module PhraseApp
98
98
 
99
99
  resp, err = send(req, status)
100
100
 
101
-
101
+
102
102
  return resp, err
103
103
  end
104
104
 
@@ -107,10 +107,10 @@ module PhraseApp
107
107
  if err != nil
108
108
  return nil, err
109
109
  end
110
-
110
+
111
111
  req["User-Agent"] = API_CLIENT_IDENTIFIER
112
112
 
113
- uri = URI.parse(PhraseApp::URL)
113
+ uri = URI.parse(PhraseApp::Auth.host)
114
114
  http = Net::HTTP.new(uri.host, uri.port)
115
115
  http.use_ssl = true
116
116
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
@@ -125,7 +125,7 @@ module PhraseApp
125
125
 
126
126
  return resp, err
127
127
  end
128
-
128
+
129
129
  def self.handleResponseStatus(resp, expectedStatus)
130
130
  case resp.code.to_i
131
131
  when expectedStatus
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module PhraseApp
2
- VERSION = '1.0.12'
2
+ VERSION = '1.0.13'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phraseapp-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - PhraseApp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-07 00:00:00.000000000 Z
11
+ date: 2015-07-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: PhraseApp API client libary
14
14
  email:
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  version: '0'
42
42
  requirements: []
43
43
  rubyforge_project:
44
- rubygems_version: 2.4.7
44
+ rubygems_version: 2.4.6
45
45
  signing_key:
46
46
  specification_version: 4
47
47
  summary: Interact with the PhraseApp API