aigu-rails 0.1 → 0.1.1

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: a2d1139d62ebf693d079e2d332c7059b3efefe2c
4
- data.tar.gz: 80fd257afe16c0e5344c816fabd8a7978bf731d3
3
+ metadata.gz: 31daeefa84babf789c32645049c0cc85efce8838
4
+ data.tar.gz: 6bd907a9940be0c86eacb1f31f801a646088fc50
5
5
  SHA512:
6
- metadata.gz: daf28ee684772ae40b65eb7a60651cc6614cde7d8736b700b9abc5b42982f677f3b281c2690d3a41404a97189eaa38457ff3d0aa4c6953506424d3bd4ab46943
7
- data.tar.gz: 1b646a3c572f789724d0b23b47b5e503b9e309c962c92215f323f6894a1f62eef7417f05b5115b9f1399cacc2cb5939df06dd4073314ec316cddf9554cb209c1
6
+ metadata.gz: 5a3a379ace0f6f8e72ae5294f532455ade8f5d2ca80a8a696816b874142a5c3bf8e05511892c35bfd1b52b04310886d17ca87dba5cba845c94bd0be35350166d
7
+ data.tar.gz: 0f74023446f08429e7dfaeeac47d61dea08ce99facc343b6b607680580022bc82c129dfc25df2ccda8d9d38a9c2ab156947c77a8036282baee703b1f00af43de
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'rspec', '~> 3.2'
24
24
  spec.add_development_dependency 'rubocop', '~> 0.31'
25
25
  spec.add_development_dependency 'phare', '~> 0.7'
26
+
27
+ spec.add_dependency 'faraday', '~> 0.9'
26
28
  end
@@ -9,16 +9,28 @@ require 'aigu-rails/version'
9
9
 
10
10
  module Aigu
11
11
  module Rails
12
+ # Constants
13
+ API_URL = 'https://accent.mirego.com'.freeze
14
+ DEFAULT_PATH = '/public_api/latest_revision'.freeze
15
+
16
+ # Errors
17
+ Error = Class.new(StandardError)
18
+
12
19
  def self.configure
13
20
  yield(self.configuration)
14
21
  end
15
22
 
16
23
  def self.configuration
17
- @configuration ||= OpenStruct.new
24
+ @configuration ||= OpenStruct.new(
25
+ api_url: API_URL,
26
+ default_path: DEFAULT_PATH
27
+ )
18
28
  end
19
29
 
20
30
  def self.reload_locales!(locale:)
21
31
  Accent::LocaleReloader.new(locale: locale).reload!
32
+ rescue
33
+ raise Error
22
34
  end
23
35
  end
24
36
  end
@@ -12,6 +12,10 @@ module Aigu
12
12
  end
13
13
  end
14
14
 
15
+ def self.connection
16
+ @connection ||= Faraday.new(url: Aigu::Rails.configuration.api_url)
17
+ end
18
+
15
19
  protected
16
20
 
17
21
  def parsed_response
@@ -22,21 +26,16 @@ module Aigu
22
26
  "#{::Rails.root}/tmp/locales.json"
23
27
  end
24
28
 
25
- def api_key
26
- Aigu::Rails.configuration.api_key
27
- end
28
-
29
29
  def response
30
- path = "/public_api/latest_revision?language=#{@locale}&render_format=json&render_filename=locales.json"
31
- uri = URI.parse('https://accent.mirego.com')
32
-
33
- http = Net::HTTP.new(uri.host, uri.port)
34
- http.use_ssl = true
35
-
36
- req = Net::HTTP::Get.new(uri.path + path)
37
- req['Authorization'] = api_key
38
-
39
- http.request(req)
30
+ self.class.connection.get do |req|
31
+ req.url Aigu::Rails.configuration.default_path
32
+ req.headers['Authorization'] = Aigu::Rails.configuration.api_key
33
+ req.params = {
34
+ language: @locale,
35
+ render_format: 'json',
36
+ render_filename: 'locales.json'
37
+ }
38
+ end
40
39
  end
41
40
  end
42
41
  end
@@ -1,5 +1,5 @@
1
1
  module Aigu
2
2
  module Rails
3
- VERSION = '0.1'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
@@ -21,9 +21,16 @@ describe Aigu::Rails do
21
21
 
22
22
  before do
23
23
  expect(Aigu::Rails::Accent::LocaleReloader).to receive(:new).with(locale: locale).and_return(locale_reloader)
24
- expect(locale_reloader).to receive(:reload!)
25
24
  end
26
25
 
27
- specify { base_class.reload_locales!(locale: locale) }
26
+ context 'without raised errors' do
27
+ before { expect(locale_reloader).to receive(:reload!) }
28
+ specify { base_class.reload_locales!(locale: locale) }
29
+ end
30
+
31
+ context 'with raised error' do
32
+ before { expect(locale_reloader).to receive(:reload!) { raise StandardError } }
33
+ it { expect { base_class.reload_locales!(locale: locale) }.to raise_error(Aigu::Rails::Error) }
34
+ end
28
35
  end
29
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aigu-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Garneau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-29 00:00:00.000000000 Z
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.9'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.9'
83
97
  description: Add support for Rails locales with aigu
84
98
  email:
85
99
  - sgarneau@mirego.com