Class: ChaskiqRubyClient::Client
- Inherits:
-
Object
- Object
- ChaskiqRubyClient::Client
- Defined in:
- lib/chaskiqRubyClient/client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#schema ⇒ Object
Returns the value of attribute schema.
-
#size ⇒ Object
Returns the value of attribute size.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize(site, token) ⇒ Client
constructor
A new instance of Client.
- #query(type, variables = {}) ⇒ Object
Constructor Details
#initialize(site, token) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/chaskiqRubyClient/client.rb', line 10 def initialize(site, token) self.token = token # Configure GraphQL endpoint using the basic HTTP network adapter. http = GraphQL::Client::HTTP.new(site) do def headers(context) # Optionally set any HTTP headers #{ "User-Agent": "My Client" } {"Authorization" => "Bearer #{context[:token]}"} end end # Fetch latest schema on init, this will make a network request @schema = GraphQL::Client.load_schema( GraphQL::Client.dump_schema( http, nil, context: { token: token } ) ) # However, it's smart to dump this to a JSON file and load from disk # # Run it from a script or rake task # GraphQL::Client.dump_schema(SWAPI::HTTP, "path/to/schema.json") # # Schema = GraphQL::Client.load_schema("path/to/schema.json") @client = GraphQL::Client.new( schema: @schema, execute: http ) end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
8 9 10 |
# File 'lib/chaskiqRubyClient/client.rb', line 8 def client @client end |
#schema ⇒ Object
Returns the value of attribute schema.
8 9 10 |
# File 'lib/chaskiqRubyClient/client.rb', line 8 def schema @schema end |
#size ⇒ Object
Returns the value of attribute size.
8 9 10 |
# File 'lib/chaskiqRubyClient/client.rb', line 8 def size @size end |
#token ⇒ Object
Returns the value of attribute token.
8 9 10 |
# File 'lib/chaskiqRubyClient/client.rb', line 8 def token @token end |
Instance Method Details
#query(type, variables = {}) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/chaskiqRubyClient/client.rb', line 45 def query(type, variables={}) self.client.query( type, { context: { token: self.token }, variables: variables }) end |