Class: Bixby::JsonRequest

Inherits:
Object
  • Object
show all
Includes:
HttpClient, Jsonify
Defined in:
lib/bixby-common/api/json_request.rb

Overview

Wraps a JSON Request

Direct Known Subclasses

EncryptedJsonRequest, SignedJsonRequest

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HttpClient

#http_get, #http_get_json, #http_post, #http_post_download, #http_post_json

Methods included from Jsonify

included, #to_json

Methods included from Hashify

#to_hash

Constructor Details

#initialize(operation, params) ⇒ JsonRequest

Create a new JsonRequest

Parameters:

  • operation (String)

    Name of operation

  • params (Array)

    Array of parameters; must ve valid JSON types



19
20
21
22
# File 'lib/bixby-common/api/json_request.rb', line 19

def initialize(operation, params)
  @operation = operation
  @params = params
end

Instance Attribute Details

#operationString

Name of operation

Returns:

  • (String)

    the current value of operation



8
9
10
# File 'lib/bixby-common/api/json_request.rb', line 8

def operation
  @operation
end

#paramsArray

Array of paramters; must be valid JSON types

Returns:

  • (Array)

    the current value of params



8
9
10
# File 'lib/bixby-common/api/json_request.rb', line 8

def params
  @params
end

Instance Method Details

#==(other) ⇒ Boolean

Test if this object is equal to some other object

Parameters:

Returns:

  • (Boolean)


46
47
48
# File 'lib/bixby-common/api/json_request.rb', line 46

def ==(other)
  operation == other.operation && params == other.params
end

#to_s(include_params = true) ⇒ String

Stringify, useful for debugging

Parameters:

  • include_params (Boolean) (defaults to: true)

    whether or not to include params in the output (default: true)

Returns:

  • (String)


29
30
31
32
33
34
35
# File 'lib/bixby-common/api/json_request.rb', line 29

def to_s(include_params=true)
  s = []
  s << "JsonRequest:#{self.object_id}"
  s << "  operation:  #{self.operation}"
  s << "  params:     " + MultiJson.dump(self.params) if include_params
  s.join("\n")
end

#to_wireObject



37
38
39
# File 'lib/bixby-common/api/json_request.rb', line 37

def to_wire
  MultiJson.dump(self)
end