lolitado 0.1.0 → 0.1.4

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
  SHA256:
3
- metadata.gz: 7215273662a496c04cf7766edd94711a0b7597b9b9aecd4e5986551617a65fc2
4
- data.tar.gz: e41b90e0441c6ef8433b4d08608c18fb5782d51d411087cad69c7e536fb4c1b0
3
+ metadata.gz: 8721d993ba93fa0b093f43e66f0ee2ee2274245dae9f887875bc4fbf3cc8cdcb
4
+ data.tar.gz: bac8a6a0683605087651cad5b68ad7980a3333806f4b28f9ba442445e8b71ec0
5
5
  SHA512:
6
- metadata.gz: 742ac304a6247c677d2cc71b443a86cef94a0cd16ee8880f5cb1634a44f66f9cd99bf092dbf6b69ccd4de57114b6990e5887ca14e05c29820e486676471911d9
7
- data.tar.gz: 64581f1c3e9871efdfa1eeaf2109766a4acc77f4e34fefe130fc275589ee43d5603fa91a403173664965f451fd57d64cd8bd613fea2a6782938578f2596f9382
6
+ metadata.gz: a34d032214ac441f52cdf393e13ad85f67215d3031c3264a43e858c40470f3b5703053d151d3bc277ae5412df843b1a0cf9319032035e559d494f4eac3716ff4
7
+ data.tar.gz: 521d296bbcd6d0d0028b241e6f951150f73b001a32d8701bd12825f090664731ee6078fce497cee10f467537986e9942b7903685312e4da158ea03aa092d6620
data/lib/lolitado/api.rb CHANGED
@@ -10,7 +10,9 @@ module Lolitado
10
10
  # @param msecs [Float] benchmark for api response time
11
11
  #
12
12
  def self.format_response response, msecs
13
- return {:response => response, :message => response.parsed_response, :status => response.code, :duration => msecs}
13
+ new_response = {:response => response, :message => response.parsed_response, :status => response.code, :duration => msecs}
14
+ response_with_hash_key = JSON.parse(JSON[new_response], symbolize_names: true)
15
+ return response_with_hash_key
14
16
  end
15
17
 
16
18
  #
@@ -37,6 +39,7 @@ module Lolitado
37
39
  end
38
40
  finish = Time.now
39
41
  msecs = (finish - start) * 1000.0
42
+ clear_headers
40
43
  # puts "RESPONSE - #{msecs}"
41
44
  return self.format_response(response, msecs)
42
45
  end
@@ -58,6 +61,13 @@ module Lolitado
58
61
  def self.new_headers
59
62
  return @new_headers
60
63
  end
64
+
65
+ #
66
+ # clear headers
67
+ #
68
+ def self.clear_headers
69
+ API.new_headers.clear unless API.new_headers.nil?
70
+ end
61
71
  end
62
72
 
63
73
  class Graph < API
@@ -71,7 +81,7 @@ module Lolitado
71
81
  # @param variables [String] input variables for graph query using
72
82
  #
73
83
  def self.request query, variables = false
74
- super(:post, '/', generate_body(query, variables))
84
+ super(:post, '', generate_body(query, variables))
75
85
  end
76
86
 
77
87
  #
@@ -90,7 +100,9 @@ module Lolitado
90
100
  else
91
101
  message = {'errors'=>response.parsed_response}
92
102
  end
93
- return {:response => response, :message => message, :status => response.code, :duration => msecs}
103
+ new_response = {:response => response, :message => message, :status => response.code, :duration => msecs}
104
+ response_with_hash_key = JSON.parse(JSON[new_response], symbolize_names: true)
105
+ return response_with_hash_key
94
106
  end
95
107
 
96
108
  #
@@ -103,7 +115,8 @@ module Lolitado
103
115
  body = {}
104
116
  body['query'] = query
105
117
  if variables
106
- if query.include?('$input')
118
+ variable_indices = query.enum_for(:scan, /(?=\$.*:)/).map { Regexp.last_match.offset(0).first }
119
+ if query.include?('$input') && variable_indices.to_a.length == 1
107
120
  body['variables'] = {'input'=>variables}
108
121
  else
109
122
  body['variables'] = variables
@@ -1,3 +1,3 @@
1
1
  module Lolitado
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/lolitado.rb CHANGED
@@ -19,8 +19,7 @@ require 'lolitado/box'
19
19
  # end
20
20
 
21
21
  # def get_details_of_a_city city_slug, locale
22
- # add_headers({'Accept-Language' => locale})
23
- # request('get', "/cities/#{city_slug}")
22
+ # request('get', "/cities/#{city_slug}", locale)
24
23
  # end
25
24
  # end
26
25
  #
@@ -33,7 +32,6 @@ require 'lolitado/box'
33
32
  # end
34
33
 
35
34
  # def user_login payload
36
- # add_headers({'Content-Type' => "application/json"})
37
35
  # query = "mutation login($input: UserLoginInput!) {userLogin(input:$input) {authToken}}"
38
36
  # graph_request(query, payload)
39
37
  # end
@@ -45,9 +43,13 @@ module Lolitado
45
43
  #
46
44
  # @param method [String] http request method
47
45
  # @param endpoint [String] http request endpoint
46
+ # @param token [String] authorization token if query needed
47
+ # @param locale [String] locale if query needed
48
48
  # @param body [String] http request body
49
49
  #
50
- def request method, endpoint, body=false
50
+ def request method, endpoint, token = false, locale = false, body=false
51
+ add_headers({'Authorization' => "Bearer #{token}"}) if token
52
+ add_headers({'Accept-Language' => locale}) if locale
51
53
  API.request(method, endpoint, body)
52
54
  end
53
55
 
@@ -55,9 +57,14 @@ module Lolitado
55
57
  # forward graph_request method from Graph class to Graph.request method
56
58
  #
57
59
  # @param query [String] graph query
60
+ # @param token [String] authorization token if query needed
61
+ # @param locale [String] locale if query needed
58
62
  # @param variables [String] input variables for graph query using
59
63
  #
60
- def graph_request query, variables = false
64
+ def graph_request query, token = false, locale = false, variables = false
65
+ add_headers({'Content-Type' => "application/json"})
66
+ add_headers({'Authorization' => "Bearer #{token}"}) if token
67
+ add_headers({'Accept-Language' => locale}) if locale
61
68
  Graph.request(query, variables)
62
69
  end
63
70
 
data/lolitado.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.license = 'MIT'
17
17
  s.require_paths = ["lib"]
18
- s.add_dependency "sequel", "~> 4.37"
18
+ s.add_dependency "sequel", "~> 5.49.0"
19
19
  s.add_dependency "net-ssh-gateway", "~> 1.2"
20
20
  s.add_dependency "httparty", "~> 0.14"
21
21
  s.add_dependency "rbnacl-libsodium", "~> 1.0.10"
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lolitado
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dolores Zhang
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2018-12-14 00:00:00.000000000 Z
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.37'
19
+ version: 5.49.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.37'
26
+ version: 5.49.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: net-ssh-gateway
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -88,7 +88,7 @@ homepage: http://github.com/doloreszhang/lolitado
88
88
  licenses:
89
89
  - MIT
90
90
  metadata: {}
91
- post_install_message:
91
+ post_install_message:
92
92
  rdoc_options: []
93
93
  require_paths:
94
94
  - lib
@@ -103,9 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubyforge_project:
107
- rubygems_version: 2.7.7
108
- signing_key:
106
+ rubygems_version: 3.2.15
107
+ signing_key:
109
108
  specification_version: 4
110
109
  summary: Lolitado DSL for database process
111
110
  test_files: []