class Masheri::RpcClient
Public Instance Methods
call_remote(method, opts = {})
click to toggle source
# File lib/masheri/rpc_client.rb, line 27 def call_remote(method, opts = {}) perform('method' => method, 'params' => Array(opts[:params]), 'id' => 1) end
config()
click to toggle source
# File lib/masheri/rpc_client.rb, line 3 def config Masheri.config end
create(type, params)
click to toggle source
Create an object
# File lib/masheri/rpc_client.rb, line 22 def create(type, params) # TODO: Handle params! call_remote [type_name, "create"].join('.') end
echo(value)
click to toggle source
Test Mashery API with echo service
# File lib/masheri/rpc_client.rb, line 8 def echo(value) call_remote('test.echo', value) end
full_url()
click to toggle source
# File lib/masheri/rpc_client.rb, line 31 def full_url build_url(config.site_id, config.key, config.signature) end
Also aliased as: url
query(string)
click to toggle source
Use the Mashery query language to grab data
# File lib/masheri/rpc_client.rb, line 17 def query(string) call_remote("object.query", params: string) end
query_builder(klass)
click to toggle source
# File lib/masheri/rpc_client.rb, line 12 def query_builder(klass) Masheri::QueryBuilder.new(klass) end
Protected Instance Methods
build_url(site_id, apikey, signature)
click to toggle source
# File lib/masheri/rpc_client.rb, line 51 def build_url(site_id, apikey, signature) query = URI.encode_www_form(apikey: apikey, sig: signature) uri = URI::HTTP.build(host: config.host, path: "/v2/json-rpc/#{site_id}", query: query.to_s) uri.scheme = "https" uri.to_s end
perform(params)
click to toggle source
# File lib/masheri/rpc_client.rb, line 39 def perform(params) JSON.parse(post!(full_url, params)) end
post!(full_url, params)
click to toggle source
# File lib/masheri/rpc_client.rb, line 43 def post!(full_url, params) ::RestClient.post(full_url, params.to_json, { "Content-Type" => "application/json", "Accept" => "text/plain", "Content-Length" => params.size }) end