public
Description: Simple wrapper for the Braintree APIs that uses Camping
Homepage: http://developer.getbraintree.com
Clone URL: git://github.com/braintree/braintree-utili-tool.git
Search Repo:
commiting query api functionality
ch0wda (author)
Wed Apr 09 13:48:04 -0700 2008
commit  ad6092e3f7211ad7812af9efe607870360937ffc
tree    7f819b55fdd41e29a2be13afdf1f8458fab57801
parent  f3dd12d99a4b12c36186170ce303ef06710a84a0
...
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
0
@@ -1 +1,10 @@
0
+*Usage:* QuickQuery is a simple wrapper around the Direct Post authentication methods of the Query APIs. It's usage is very similar to typing out a query string in the browser, except you'll receive the response on this page in a table along with the query string, as it was generated.
0
+
0
+Type in your username and password. Type out any @key=value@ pairs for the item you are searching for. See the "Query API":http://developer.getbraintree.com/apis/3-query for a complete list of values.
0
+
0
+A simple example would look like this: @lastname=Dobbs&condition=pending,complete@.
0
+
0
+Make sure to escape the values, for example: @lastname=Van Houten@ should be @lastname=Van%20Houten@.
0
+
0
+Please excuse the formatting of the response, we're working on getting something that looks a little better.
...
1
2
3
4
 
 
5
6
7
...
80
81
82
83
 
84
85
86
87
88
89
90
91
92
...
89
90
91
92
93
 
 
94
 
 
95
96
97
98
99
 
 
 
100
101
 
 
 
 
 
102
103
104
105
 
 
 
 
 
 
 
 
106
107
108
109
110
...
196
197
198
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
200
201
...
283
284
285
 
 
286
287
288
...
320
321
322
323
324
325
326
327
...
336
337
338
339
340
341
342
343
 
344
345
346
...
367
368
369
370
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
371
372
373
...
1
2
 
 
3
4
5
6
7
...
80
81
82
 
83
84
85
86
87
88
89
90
91
92
...
89
90
91
 
 
92
93
94
95
96
97
98
99
 
 
100
101
102
103
 
104
105
106
107
108
109
 
110
111
112
113
114
115
116
117
118
119
120
 
121
122
123
...
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
...
314
315
316
317
318
319
320
321
...
353
354
355
 
356
357
358
359
...
368
369
370
 
371
372
373
 
374
375
376
377
...
398
399
400
 
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
0
@@ -1,7 +1,7 @@
0
 #!/usr/bin/env ruby
0
 
0
-%w( rubygems mime/types camping cgi
0
- digest/md5 net/https redcloth ).each { |lib| require lib }
0
+%w( rubygems mime/types camping xmlsimple
0
+ digest/md5 net/https redcloth pp).each { |lib| require lib }
0
 
0
 Camping.goes :UtiliTool
0
 
0
@@ -80,7 +80,7 @@
0
     # 'quick_query', the key will be dropped, and only the value will be used.
0
     def create_uri_string_from_form_inputs(form_inputs)
0
       uri_array = []
0
- form_inputs.delete_if { |key,value| value == "" }
0
+ form_inputs.delete_if { |key,value| value.strip == "" }
0
       form_inputs.each do |key, value|
0
         key == 'quick_query' ? uri_array << value : uri_array << "#{key}=#{value}"
0
       end
0
0
0
0
0
0
0
@@ -89,22 +89,35 @@
0
   end
0
 
0
   class GatewayResponse < Braintree
0
- attr_accessor :response_body
0
- def initialize(response_body)
0
+ attr_accessor :response_body, :format, :formatted_response_body
0
+ def initialize(response_body, format = nil)
0
       self.response_body = response_body
0
+ self.format = format
0
+ self.formatted_response_body = format_response_body
0
     end
0
 
0
     def to_hash
0
- response_hash = { }
0
- self.response_body.split("&").each do |pair|
0
+ unless self.format.nil?
0
+ response_hash = { }
0
+ self.response_body.split("&").each do |pair|
0
         pair_array = pair.split("=")
0
- response_hash[pair_array[0]] = pair_array[1]
0
+ response_hash[pair_array[0]] = pair_array[1]
0
+ end
0
+ response_hash.delete_if { |key, value| value.nil? }
0
+ else
0
+ response_hash = XmlSimple.xml_in(self.response_body, { 'SupressEmpty' => true, 'NormaliseSpace' => 2 })
0
       end
0
- response_hash.delete_if { |key, value| value.nil? }
0
       return response_hash
0
     end
0
+
0
+ private
0
+ def format_response_body
0
+ xml_oo = XmlSimple.xml_in(self.response_body, { 'SuppressEmpty' => true })
0
+ xml_oo_out = XmlSimple.xml_out(xml_oo, { 'NoEscape' => true })
0
+ formatted = xml_oo_out.gsub("<", "&lt;").gsub(">", "&gt;")
0
+ return formatted
0
+ end
0
   end
0
-
0
 end
0
 
0
 module UtiliTool::Controllers
0
@@ -196,6 +209,24 @@
0
       end
0
     end
0
   end
0
+
0
+ class QuickQuery < R '/quick_query'
0
+ include Responder
0
+ def get
0
+ @gateway_request = GatewayRequest.new({ :api => "query" })
0
+ respond_to do |format|
0
+ format.html { render :quick_query }
0
+ end
0
+ end
0
+
0
+ def post
0
+ @gateway_request = GatewayRequest.new( { :api, "query"}, input )
0
+ @gateway_response = GatewayResponse.new(@gateway_request.response)
0
+ respond_to do |format|
0
+ format.html { render :quick_query }
0
+ end
0
+ end
0
+ end
0
   
0
   class Assets < R('/static/(.+)')
0
     PATH = File.expand_path("#{File.dirname(__FILE__)}")
0
@@ -283,6 +314,8 @@
0
         :accesskey => "M" }
0
       li { a "QuickGet", :href => R(QuickGet), :title => "QuickGet",
0
         :accesskey => "G"}
0
+ li { a "QuickQuery", :href => R(QuickQuery), :title => "QuickQuery",
0
+ :accesskey => "Q"}
0
     end
0
   end
0
 
0
@@ -320,7 +353,6 @@
0
         end
0
       end
0
     end
0
-
0
     form({ :method => 'post', :action => R(Hasher)}) do
0
       fieldset do
0
         legend "Input Values to Hash"
0
0
@@ -336,11 +368,10 @@
0
         input :type => 'submit', :value => 'Submit'
0
       end
0
     end
0
-
0
   end
0
 
0
   def quick_get
0
- h2 "QuickGet Query"
0
+ h2 "QuickGet"
0
     div.static do; static_content("quick_get"); end
0
     unless @gateway_response.nil?
0
       div.response do
0
@@ -367,7 +398,34 @@
0
             input :type => 'text', :name => "username" }
0
         p { label 'Password', :for => 'password'; br;
0
           input :type => 'text', :name => "password" }
0
- p { label 'Query', :for => 'quick_get_query'; br;
0
+ p { label 'Query', :for => 'quick_query'; br;
0
+ textarea :name => "quick_query", :rows => 5, :cols => 55 }
0
+ input :type => 'submit', :value => 'Submit'
0
+ end
0
+ end
0
+ end
0
+
0
+ def quick_query
0
+ h2 "QuickQuery"
0
+ div.static do; static_content("quick_query"); end
0
+ unless @gateway_response.nil?
0
+ div.response do
0
+ h3 "Raw Gateway Response"
0
+ p "Better formatting is on it's way."
0
+ p { code { word_wrap(@gateway_request.uri_string) }}
0
+ code do
0
+ @gateway_response.formatted_response_body
0
+ end
0
+ end
0
+ end
0
+ form({ :method => 'post', :action => R(QuickQuery)}) do
0
+ fieldset do
0
+ legend "Input a query string"
0
+ p { label 'Username', :for => 'username'; br;
0
+ input :type => 'text', :name => "username" }
0
+ p { label 'Password', :for => 'password'; br;
0
+ input :type => 'text', :name => "password" }
0
+ p { label 'Query', :for => 'quick_query'; br;
0
             textarea :name => "quick_query", :rows => 5, :cols => 55 }
0
         input :type => 'submit', :value => 'Submit'
0
       end

Comments

    No one has commented yet.