[SCM] ci-tooling packaging branch, master, updated. a9d5c7726915ff1ff3dcb0be2de85114532f2794
Harald Sitter
apachelogger-guest at moszumanska.debian.org
Wed Dec 10 07:15:26 UTC 2014
Gitweb-URL: http://git.debian.org/?p=pkg-kde/ci-tooling.git;a=commitdiff;h=da82021
The following commit has been merged in the master branch:
commit da8202178f7a4b9e93bc7ccb14540a8b243f6b60
Author: Harald Sitter <sitter at kde.org>
Date: Wed Dec 10 08:15:03 2014 +0100
cleanup get/post mess, lp module now has both functions and uses token
---
lib/lp.rb | 38 +++++++++++++++++++++++++-------------
1 file changed, 25 insertions(+), 13 deletions(-)
diff --git a/lib/lp.rb b/lib/lp.rb
index 444b15f..1742d17 100644
--- a/lib/lp.rb
+++ b/lib/lp.rb
@@ -2,16 +2,16 @@ module Launchpad
require 'json'
require 'ostruct'
require 'net/http'
-
+
require 'oauth'
require 'oauth/signature/plaintext'
-
+
@token = nil
-
+
def self.token()
return @token
end
-
+
def self.authenticate()
consumer_options = {
:signature_method => 'PLAINTEXT',
@@ -49,6 +49,18 @@ module Launchpad
return @token
end
+ def self.get(uri)
+ if @token
+ return @token.get(uri.path)
+ end
+ return Net::HTTP.get(uri)
+ end
+
+ def self.post(uri)
+ # Posting always requires a token.
+ return @token.post(uri.path)
+ end
+
# Condom for launchpad.
# Unlike launchpadlib we strive for minimal overhead by minimal validation.
# Launchpadlib internally will lookup the representation spec through WADL
@@ -60,27 +72,27 @@ module Launchpad
# - TODO: Property changes not implemented. Would probably go through a save accessor.
class Rubber < OpenStruct
def method_missing(name, *args, &block)
- # puts "++++++++++++++ method missing! #{name}"
+# puts "++++++++++++++ method missing! #{name}"
# Pointer to different URL reflecting a different object.
if self["#{name}_link"]
- data = Net::HTTP.get(URI(self.send("#{name}_link")))
+ data = Launchpad::get(URI(self.send("#{name}_link")))
return JSON::parse(data, :object_class => Rubber)
end
# TODO: params hash should get values checked if they respond to self_link and if so use that instead
-
+
# Pointer to a different URL reflecting a collection of things.
if self["#{name}_collection_link"]
ret = []
uri = URI(self.send("#{name}_collection_link"))
loop do
- obj = Rubber::from_json(Net::HTTP.get(uri))
+ obj = Rubber::from_json(Launchpad::get(uri))
ret += obj.entries
return ret unless obj['next_collection_link']
uri = URI(obj.next_collection_link)
end
end
-
+
# Try to call as a 'function' on the API
if name.to_s.end_with?('!') # foo! causes a post
uri = URI(self['self_link'])
@@ -89,7 +101,7 @@ module Launchpad
params['ws.op']= name.to_s.chomp('!')
uri.query = URI.encode_www_form(params)
loop do
- Launchpad::token.post(uri.path, uri.query)
+ Launchpad::post(uri.path, uri.query)
return nil
end
else # foo causes a get
@@ -100,7 +112,7 @@ module Launchpad
params['ws.op'] = name.to_s
uri.query = URI.encode_www_form(params)
loop do
- obj = Rubber::from_json(Net::HTTP.get(uri))
+ obj = Rubber::from_json(Launchpad::get(uri))
if obj['entries']
ret += obj.entries
else
@@ -111,14 +123,14 @@ module Launchpad
end
end
end
-
+
def self.from_json(json)
return JSON::parse(json, :object_class => Rubber)
end
def self.from_url(url)
uri = URI(url)
- reply = Launchpad::token.get(uri.path)
+ reply = Launchpad::get(uri.path)
return Rubber::from_json(reply.body)
end
end
--
ci-tooling packaging
More information about the pkg-kde-commits
mailing list