Class: RemoteFactoryGirl::Http

Inherits:
Object
  • Object
show all
Defined in:
lib/remote_factory_girl/http.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, params, http_lib = RestClient) ⇒ Http

Returns a new instance of Http.



15
16
17
18
19
20
# File 'lib/remote_factory_girl/http.rb', line 15

def initialize(config, params, http_lib = RestClient)
  config.raise_if_host_not_set
  @config   = config
  @params   = params
  @http_lib = http_lib
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



13
14
15
# File 'lib/remote_factory_girl/http.rb', line 13

def config
  @config
end

#http_libObject (readonly)

Returns the value of attribute http_lib.



13
14
15
# File 'lib/remote_factory_girl/http.rb', line 13

def http_lib
  @http_lib
end

#paramsObject (readonly)

Returns the value of attribute params.



13
14
15
# File 'lib/remote_factory_girl/http.rb', line 13

def params
  @params
end

#response_jsonObject (readonly)

Returns the value of attribute response_json.



13
14
15
# File 'lib/remote_factory_girl/http.rb', line 13

def response_json
  @response_json
end

Class Method Details

.get(config, params, http_lib = RestClient) ⇒ Object



9
10
11
# File 'lib/remote_factory_girl/http.rb', line 9

def self.get(config, params, http_lib = RestClient)
  new(config, params, http_lib).get
end

.post(config, params, http_lib = RestClient) ⇒ Object



5
6
7
# File 'lib/remote_factory_girl/http.rb', line 5

def self.post(config, params, http_lib = RestClient)
  new(config, params, http_lib).post
end

Instance Method Details

#getObject



22
23
24
25
# File 'lib/remote_factory_girl/http.rb', line 22

def get
  @response_json = http_lib.get config.home_url, params.merge!(content_type: :json, accept: :json)
  self
end

#postObject



27
28
29
30
# File 'lib/remote_factory_girl/http.rb', line 27

def post
  @response_json = http_lib.post config.home_url, params, content_type: :json, accept: :json
  self
end

#to_hashObject



32
33
34
# File 'lib/remote_factory_girl/http.rb', line 32

def to_hash
  JSON.parse(response_json)
end