class GramAccountMocker

Constants

DEFAULT_GRAM_ACCOUNT

Attributes

attributes[R]

Public Class Methods

for(attr:{},auth: nil) click to toggle source
# File lib/gram_v2_client/rspec/gram_account_mocker.rb, line 39
def self.for(attr:{},auth: nil)
  string_hash=attr.inject({}){|memo,(k,v)| memo[k.to_s] = v; memo}
  self.new(DEFAULT_GRAM_ACCOUNT.merge(string_hash),auth)
end
http_basic_auth_header(user,password) click to toggle source
# File lib/gram_v2_client/rspec/gram_account_mocker.rb, line 77
def self.http_basic_auth_header(user,password)
  "Basic "+Base64.encode64("#{user}:#{password}").chomp
end
new(attr={},auth=nil) click to toggle source
# File lib/gram_v2_client/rspec/gram_account_mocker.rb, line 30
def initialize(attr={},auth=nil)
  @auth=auth
  @attributes=attr
end
reset!() click to toggle source
# File lib/gram_v2_client/rspec/gram_account_mocker.rb, line 73
def self.reset!
  ActiveResource::HttpMock.reset!
end

Public Instance Methods

mock_get_request(with_password: false) click to toggle source
# File lib/gram_v2_client/rspec/gram_account_mocker.rb, line 50
def mock_get_request(with_password: false)
  uri=uri_for_get_request(with_password: with_password)
  ActiveResource::HttpMock.respond_to({},false) do |mock|
    mock.get uri, {"Authorization"=>authorization_header,'Accept' => 'application/json'}, attributes.to_json, 200
  end
end
mock_put_request() click to toggle source
# File lib/gram_v2_client/rspec/gram_account_mocker.rb, line 66
def mock_put_request()
  uri= "/api/v2/accounts/#{uuid}.json"
  ActiveResource::HttpMock.respond_to({},false) do |mock|
    mock.put uri, {"Authorization"=>authorization_header,'Content-Type' => 'application/json'}, attributes.to_json, 200
  end
end
mock_search_request_for(param,value=nil,response=[attributes]) click to toggle source
# File lib/gram_v2_client/rspec/gram_account_mocker.rb, line 57
def mock_search_request_for(param,value=nil,response=[attributes])
  value||=attributes[param.to_s]
  value=URI.escape(URI.escape(value.to_s),"@")
  response=response.to_json unless response.is_a? String
  ActiveResource::HttpMock.respond_to({},false) do |mock|
    mock.get "/api/v2/accounts.json?#{param.to_s}=#{value}", {"Authorization"=>authorization_header,'Accept' => 'application/json'}, response, 200
  end
end
uri_for_get_request(with_password: false) click to toggle source
# File lib/gram_v2_client/rspec/gram_account_mocker.rb, line 44
def uri_for_get_request(with_password: false)
  uri= "/api/v2/accounts/#{uuid}.json"
  uri+= "?show_password_hash=true" if with_password
  uri
end
uuid() click to toggle source
# File lib/gram_v2_client/rspec/gram_account_mocker.rb, line 35
def uuid
  @attributes["uuid"]
end

Private Instance Methods

authorization_header() click to toggle source
# File lib/gram_v2_client/rspec/gram_account_mocker.rb, line 83
def authorization_header
  @auth
end