activegraphql 0.1.0 → 0.2.0

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: 657360098f58cecb708293738e5ecf43bc40890e
4
- data.tar.gz: 51e15e8a81e7100617f665ec94b4cc4b27612546
3
+ metadata.gz: a44463407791a95197a628418f23f722933b427c
4
+ data.tar.gz: 3adb7777bcdab68b3297e387d9b6edf18f029df4
5
5
  SHA512:
6
- metadata.gz: 9a5233fa7a1e4d9a6f31202d751a24b4fd145f09552958885d4913cce9cb2f20bc2e29c25cbcd200b13c3bb9ffb8ca94d88599ad5c331407b27606063b2cfef9
7
- data.tar.gz: 496784159351d5efbbde0cc844ab09d6db13d8f3e4ca4d4d6270abe151069d3ade3a2258451291be49a9da69c1e8ffe6d5327199a87bd67a7f07e5e9092fd270
6
+ metadata.gz: 1c0462e5de2eaa132959fda32d9bcb4a964b4f4f858e4618c46f8359ce371290dba2f1732d1a240b073b31a8dd193e40abb7b445994319b9bce55f04eba4472e
7
+ data.tar.gz: 528eae33a1f2815cdf3e16c9ab64f5afcbc579a83d66a4be0a87ab49048dce312fc0cc67137ea81010979e7440365ae980ae83853691ca31fd54ba6e39baf2af
data/README.md CHANGED
@@ -72,3 +72,18 @@ Resolved query:
72
72
  ```
73
73
  { myModel("id": "5") { id, name, nestedObject { description } } }
74
74
  ```
75
+
76
+ ## Localisation support
77
+ Any fetcher provides the `in_locale(locale)` method that makes the call to include the `HTTP_ACCEPT_LANGUAGE` header to get the content localized in case of the service supporting it.
78
+
79
+ ```ruby
80
+ >> MyModel.all.in_locale(:en).fetch(:some_attribute).first.some_attribute
81
+ => "This is my text"
82
+
83
+ >> MyModel.all.in_locale(:es).fetch(:some_attribute).first.some_attribute
84
+ => "Este es mi texto"
85
+
86
+ # Also accepts strings as locale
87
+ >> MyModel.all.in_locale('es_ES').fetch(:some_attribute).first.some_attribute
88
+ => "Este es mi texto"
89
+ ```
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{Ruby client for GraphQL services}
13
13
  spec.description = %q{}
14
- spec.homepage = 'https://github.com/wakoopa/active-graphql'
14
+ spec.homepage = 'https://github.com/wakoopa/activegraphql'
15
15
  spec.license = 'MIT'
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -8,7 +8,15 @@ module ActiveGraphQL
8
8
 
9
9
  def initialize(attrs)
10
10
  super(attrs)
11
- self.query = Query.new(url: url, action: action, params: params)
11
+ end
12
+
13
+ def query
14
+ @query ||= Query.new(url: url, action: action, params: params)
15
+ end
16
+
17
+ def in_locale(locale)
18
+ query.locale = locale if locale.present?
19
+ self
12
20
  end
13
21
 
14
22
  def fetch(*graph)
@@ -21,7 +29,7 @@ module ActiveGraphQL
21
29
  when Array
22
30
  response.map { |h| klass.new(h) }
23
31
  else
24
- fail Error, "Unexpected response for query: #{response}"
32
+ raise Error, "Unexpected response for query: #{response}"
25
33
  end
26
34
  end
27
35
  end
@@ -4,19 +4,25 @@ require 'activegraphql/support/fancy'
4
4
 
5
5
  module ActiveGraphQL
6
6
  class Query < Support::Fancy
7
- attr_accessor :url, :action, :params, :graph, :response
7
+ attr_accessor :url, :action, :params, :locale, :graph, :response
8
8
 
9
9
  class ServerError < StandardError; end
10
10
 
11
11
  def get(*graph)
12
12
  self.graph = graph
13
13
 
14
- self.response = HTTParty.get(url, query: { query: to_s })
14
+ self.response = HTTParty.get(url, request_options)
15
15
 
16
16
  raise(ServerError, response_error_messages) if response_errors.present?
17
17
  response_data
18
18
  end
19
19
 
20
+ def request_options
21
+ { query: { query: to_s } }.tap do |opts|
22
+ opts.merge!(headers: { 'accept_language' => locale.to_s }) if locale.present?
23
+ end
24
+ end
25
+
20
26
  def response_data
21
27
  return unless response['data']
22
28
  to_snake_case(response['data'][qaction])
@@ -1,3 +1,3 @@
1
1
  module ActiveGraphQL
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activegraphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wakoopa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-07 00:00:00.000000000 Z
11
+ date: 2016-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -117,7 +117,7 @@ files:
117
117
  - lib/activegraphql/query.rb
118
118
  - lib/activegraphql/support/fancy.rb
119
119
  - lib/activegraphql/version.rb
120
- homepage: https://github.com/wakoopa/active-graphql
120
+ homepage: https://github.com/wakoopa/activegraphql
121
121
  licenses:
122
122
  - MIT
123
123
  metadata: {}