Skip to content

Instantly share code, notes, and snippets.

@davidji99
Last active August 29, 2015 14:25
Show Gist options
  • Save davidji99/b64b9b08b1a0acfa08a9 to your computer and use it in GitHub Desktop.
Save davidji99/b64b9b08b1a0acfa08a9 to your computer and use it in GitHub Desktop.

Revisions

  1. @amirrajan amirrajan revised this gist May 27, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion getpost.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    module HTTPStuff
    def self.post(path, payload)
    uri = construct_uripath
    uri = construct_uri path
    http = Net::HTTP.new(uri.host, uri.port)
    req = Net::HTTP::Post.new(uri.path)
    req.body = payload.to_json
  2. @amirrajan amirrajan created this gist Apr 12, 2012.
    31 changes: 31 additions & 0 deletions getpost.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    module HTTPStuff
    def self.post(path, payload)
    uri = construct_uripath
    http = Net::HTTP.new(uri.host, uri.port)
    req = Net::HTTP::Post.new(uri.path)
    req.body = payload.to_json
    req["Authorization"] ='SOMEAUTH'
    req["Content-Type"] = "application/json"
    print http.request(req)
    end

    def self.construct_uri(path)
    return URI.parse("http://localhost:10000/" + path)
    end

    def self.get(path)
    uri = construct_uri path
    http = Net::HTTP.new(uri.host, uri.port)
    req = Net::HTTP::Get.new(uri.path)
    req["Authorization"] ='SOMEAUTH'
    print http.request(req)
    end

    def self.print(response)
    begin
    puts JSON.pretty_generate(JSON.parse(response.body))
    rescue
    puts response
    end
    end
    end