Class: InstagramUpload::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/instagram_upload/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent) ⇒ Request

Returns a new instance of Request.



5
6
7
8
# File 'lib/instagram_upload/request.rb', line 5

def initialize(agent)
  @agent = agent
  @cookies = Tempfile.new('cookies')
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



3
4
5
# File 'lib/instagram_upload/request.rb', line 3

def agent
  @agent
end

#cookiesObject (readonly)

Returns the value of attribute cookies.



3
4
5
# File 'lib/instagram_upload/request.rb', line 3

def cookies
  @cookies
end

Instance Method Details

#post(url, body) {|http| ... } ⇒ Object

Yields:

  • (http)


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/instagram_upload/request.rb', line 10

def post(url, body)
  http = Curl::Easy.new(url)
  http.headers['User-Agent'] = agent.user_agent
  http.verbose = true
  http.follow_location = true
  http.enable_cookies = true

  yield(http) if block_given?

  http.post(body)

  JSON.parse(http.body).tap { http.close }
end