Class: ZenfolioAPI::HTTP

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

Instance Method Summary collapse

Constructor Details

#initializeHTTP

Returns a new instance of HTTP.



4
5
6
# File 'lib/ZenfolioAPI/http.rb', line 4

def initialize
	@api_url = "https://api.zenfolio.com/api/1.7/zfapi.asmx"
end

Instance Method Details

#POST(method, params = {}, token = nil) ⇒ Object

Author:

  • David Slone



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ZenfolioAPI/http.rb', line 11

def POST method, params = {}, token = nil
	@api_body = {:method => method, :params => params, :id => 1}

	url = URI.parse(@api_url) 
	post = Net::HTTP::Post.new(url.path) 
	http = Net::HTTP.new(url.host, url.port)
	http.use_ssl = true
	#http.set_debug_output $stderr

	post['X-Zenfolio-User-Agent'] = 'Acme PhotoEdit plugin for Zenfolio v1.0'
	post['User-Agent'] = 'Acme PhotoEdit plugin for Zenfolio v1.0'
	post['X-Zenfolio-Token'] = token unless token.nil?
	post.content_type = 'application/json'
	post.body = @api_body.to_json

	response = http.start {|http| http.request(post) }
	@body = JSON.parse(response.body)
end