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 +4 -4
- data/README.md +15 -0
- data/activegraphql.gemspec +1 -1
- data/lib/activegraphql/fetcher.rb +10 -2
- data/lib/activegraphql/query.rb +8 -2
- data/lib/activegraphql/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a44463407791a95197a628418f23f722933b427c
|
4
|
+
data.tar.gz: 3adb7777bcdab68b3297e387d9b6edf18f029df4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
+
```
|
data/activegraphql.gemspec
CHANGED
@@ -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/
|
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
|
-
|
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
|
-
|
32
|
+
raise Error, "Unexpected response for query: #{response}"
|
25
33
|
end
|
26
34
|
end
|
27
35
|
end
|
data/lib/activegraphql/query.rb
CHANGED
@@ -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,
|
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])
|
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.
|
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-
|
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/
|
120
|
+
homepage: https://github.com/wakoopa/activegraphql
|
121
121
|
licenses:
|
122
122
|
- MIT
|
123
123
|
metadata: {}
|