Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 5017669d4043eea2600bfa1e1f7d5cf7101d1d57 Anders Törnqvist committed Mar 6, 2011
Showing with 3,465 additions and 0 deletions.
  1. +8 −0 .gitignore
  2. +3 −0 .metrics
  3. +4 −0 Gemfile
  4. +112 −0 Gemfile.lock
  5. +21 −0 Rakefile
  6. +161 −0 example/chargify.rb
  7. +90 −0 example/dns_simple.rb
  8. +18 −0 example/google.rb
  9. +50 −0 example/google_shortener.rb
  10. +37 −0 example/google_translate.rb
  11. +110 −0 lib/blankslate.rb
  12. +189 −0 lib/resto.rb
  13. +56 −0 lib/resto/attributes.rb
  14. +34 −0 lib/resto/extra/copy.rb
  15. +26 −0 lib/resto/extra/delegation.rb
  16. +56 −0 lib/resto/extra/hash_args.rb
  17. +20 −0 lib/resto/format.rb
  18. +11 −0 lib/resto/format/default.rb
  19. +30 −0 lib/resto/format/json.rb
  20. +14 −0 lib/resto/format/plain.rb
  21. +25 −0 lib/resto/format/xml.rb
  22. +49 −0 lib/resto/property.rb
  23. +46 −0 lib/resto/property/handler.rb
  24. +29 −0 lib/resto/property/integer.rb
  25. +19 −0 lib/resto/property/string.rb
  26. +74 −0 lib/resto/request/base.rb
  27. +66 −0 lib/resto/request/factory.rb
  28. +53 −0 lib/resto/request/header.rb
  29. +126 −0 lib/resto/request/option.rb
  30. +50 −0 lib/resto/request/uri.rb
  31. +69 −0 lib/resto/response/base.rb
  32. +44 −0 lib/resto/translator/request_factory.rb
  33. +28 −0 lib/resto/translator/response_factory.rb
  34. +37 −0 lib/resto/validate.rb
  35. +39 −0 lib/resto/validate/inclusion.rb
  36. +36 −0 lib/resto/validate/length.rb
  37. +24 −0 lib/resto/validate/presence.rb
  38. +5 −0 lib/resto/version.rb
  39. +8 −0 readme.markdown
  40. +40 −0 resto.gemspec
  41. +58 −0 spec/resto/extra/copy_spec.rb
  42. +71 −0 spec/resto/extra/hash_args_spec.rb
  43. +24 −0 spec/resto/format/default_spec.rb
  44. +29 −0 spec/resto/format/json_spec.rb
  45. +21 −0 spec/resto/format/plain_spec.rb
  46. +13 −0 spec/resto/format/xml_spec.rb
  47. +57 −0 spec/resto/property/handler_spec.rb
  48. +67 −0 spec/resto/property/integer_spec.rb
  49. +60 −0 spec/resto/property_spec.rb
  50. +253 −0 spec/resto/request/base_spec.rb
  51. +114 −0 spec/resto/request/factory_spec.rb
  52. +93 −0 spec/resto/translator/response_factory_spec.rb
  53. +102 −0 spec/resto/validate/presence_spec.rb
  54. +531 −0 spec/resto_spec.rb
  55. +51 −0 spec/spec_helper.rb
  56. +4 −0 todo.txt
@@ -0,0 +1,8 @@
+pkg/*
+*.gem
+.bundle
+.rvmrc
+coverage
+tmp
+.DS_Store
+example/key_setup.rb
@@ -0,0 +1,3 @@
+MetricFu::Configuration.run do |config|
+ config.metrics -= [:rcov]
+end
@@ -0,0 +1,4 @@
+source :gemcutter
+
+# Specify your gem's dependencies in resto.gemspec
+gemspec
@@ -0,0 +1,112 @@
+PATH
+ remote: .
+ specs:
+ resto (0.0.1)
+ yajl-ruby (= 0.7.8)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ Saikuro (1.1.0)
+ abstract (1.0.0)
+ activesupport (3.0.4)
+ addressable (2.2.2)
+ arrayfields (4.7.4)
+ chronic (0.2.3)
+ hoe (>= 1.2.1)
+ churn (0.0.13)
+ chronic (>= 0.2.3)
+ hirb
+ json_pure
+ main
+ ruby_parser (~> 2.0.4)
+ sexp_processor (~> 3.0.3)
+ code-cleaner (0.8.2)
+ colored (1.2)
+ crack (0.1.8)
+ diff-lcs (1.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ fattr (2.2.0)
+ flay (1.4.1)
+ ruby_parser (~> 2.0)
+ sexp_processor (~> 3.0)
+ flog (2.5.0)
+ ruby_parser (~> 2.0)
+ sexp_processor (~> 3.0)
+ haml (3.0.25)
+ hirb (0.3.6)
+ hoe (2.9.1)
+ rake (>= 0.8.7)
+ i18n (0.5.0)
+ json_pure (1.5.1)
+ main (4.4.0)
+ arrayfields (>= 4.7.4)
+ fattr (>= 2.1.0)
+ metric_fu (2.0.1)
+ Saikuro (>= 1.1.0)
+ activesupport (>= 2.0.0)
+ chronic (~> 0.2.3)
+ churn (>= 0.0.7)
+ flay (>= 1.2.1)
+ flog (>= 2.2.0)
+ rails_best_practices (>= 0.3.16)
+ rcov (>= 0.8.3.3)
+ reek (>= 1.2.6)
+ roodi (>= 2.1.0)
+ metrical (0.0.4)
+ activesupport
+ metric_fu (~> 2.0.1)
+ rails_best_practices (0.7.0)
+ activesupport
+ colored (~> 1.2)
+ erubis (~> 2.6.6)
+ haml (~> 3.0.18)
+ i18n
+ ruby-progressbar (~> 0.0.9)
+ ruby_parser (~> 2.0.4)
+ rake (0.8.7)
+ rcov (0.9.9)
+ reek (1.2.8)
+ ruby2ruby (~> 1.2)
+ ruby_parser (~> 2.0)
+ sexp_processor (~> 3.0)
+ roodi (2.1.0)
+ ruby_parser
+ rspec (2.0.1)
+ rspec-core (~> 2.0.1)
+ rspec-expectations (~> 2.0.1)
+ rspec-mocks (~> 2.0.1)
+ rspec-core (2.0.1)
+ rspec-expectations (2.0.1)
+ diff-lcs (>= 1.1.2)
+ rspec-mocks (2.0.1)
+ rspec-core (~> 2.0.1)
+ rspec-expectations (~> 2.0.1)
+ ruby-progressbar (0.0.9)
+ ruby2ruby (1.2.5)
+ ruby_parser (~> 2.0)
+ sexp_processor (~> 3.0)
+ ruby_parser (2.0.5)
+ sexp_processor (~> 3.0)
+ sexp_processor (3.0.5)
+ simplecov (0.4.0)
+ simplecov-html (~> 0.4.0)
+ simplecov-html (0.4.3)
+ webmock (1.3.5)
+ addressable (>= 2.1.1)
+ crack (>= 0.1.7)
+ yajl-ruby (0.7.8)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bundler (>= 1.0.0)
+ code-cleaner (= 0.8.2)
+ metrical
+ reek
+ resto!
+ rspec (>= 2.0.1)
+ simplecov
+ webmock (= 1.3.5)
@@ -0,0 +1,21 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
+
+$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
+
+require "resto/version"
+
+desc "open console (require 'resto')"
+task :c do
+ system "irb -I lib -r resto"
+end
+
+desc "adds encoding utf-8.."
+task :clean do
+ system "code-cleaner . --encoding=utf-8"
+end
+
+desc "Runs all the specs."
+task :spec => :clean do
+ system "bundle exec rspec spec"
+end
@@ -0,0 +1,161 @@
+# encoding: utf-8
+$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
+require File.expand_path(File.join(File.dirname(__FILE__), 'key_setup.rb'))
+
+require 'resto'
+require 'pp'
+
+# http://docs.chargify.com/api-authentication
+# http://docs.chargify.com/api-introduction
+# http://docs.chargify.com/api-resources
+class Chargify
+ include Resto
+
+ resto_request do
+ format :json, :extension => true
+ basic_auth(:username => API_KEY, :password => API_PASSWORD)
+ host 'https://dns-parrot.chargify.com/'
+ end
+
+ resto_response do
+ format :json
+ end
+end
+
+# http://docs.chargify.com/api-products
+class Product < Chargify
+ resource_identifier :id
+ property :id, Integer
+ property :price_in_cents, Integer
+ property :interval, Integer
+ property :created_at, String
+ property :name, String
+
+ resto_request do
+ path 'products'
+ translator [:product]
+ end
+
+ resto_response do
+ translator [:product]
+ end
+
+end
+
+#puts "products ************************"
+#products = Product.all
+#puts products.size
+#puts products.first.attributes
+#product = products.first
+##
+#puts "product.get(#{product.id}) ***************"
+#product = Product.get(product.id)
+#puts product.attributes
+
+#puts "\n\n\n"
+
+class Customer < Chargify
+
+ # The id is the unique identifier for this customer within Chargify
+ resource_identifier :id
+ property :id, Integer #{ validate_presence }
+ property :first_name, String #{ validate_presence }
+ property :last_name, String #{ validate_presence }
+ property :email, String #{ validate_presence }
+ property :organization, String
+ property :created_at, String
+ property :updated_at, String
+
+ resto_request do
+ path 'customers'
+ translator [:customer]
+ end
+
+ resto_response do
+ translator [:customer]
+ end
+end
+
+body = {:first_name =>"Anders ska bort",
+ :last_name => "Dum användare",
+ :email => "anders.tornqvist@elabs.se" }
+
+#puts "Customer.post(body)"
+#customer = Customer.post(body)
+#puts customer.attributes
+#puts "\n"
+
+#Customer deletion is not currently supported
+#(you will receive a 403 Forbidden response
+#puts "Customer.delete(customer.id)"
+#removed = Customer.delete(customer.id)
+#puts removed.inspect
+#puts removed.code
+#puts removed.body
+
+
+#puts "customers **************"
+#customers = Customer.all
+#puts customers.size
+#customers.each { |customer| puts customer.attributes; puts "\n" }
+#customer = customers.first
+##
+#puts "Customer.get(#{customer.id}) *************"
+#customer = Customer.get(customer.id)
+#puts customer.attributes
+
+#puts "\n\n"
+
+
+# http://docs.chargify.com/api-subscriptions
+# curl -u <api_key>:x -H Accept:application/json -H
+# Content-Type:application/json https://acme.chargify.com/subscriptions.json
+class Subscription < Chargify
+
+ resource_identifier :id
+ property :id, Integer
+ property :product_id, Integer
+ property :customer_id, Integer
+ property :cancellation_message, String
+ property :state, String
+
+ resto_request do
+ path '/subscriptions'
+ translator [:subscription]
+ end
+
+ resto_response do
+ translator [:subscription]
+ end
+
+end
+
+attributes = {
+ :product_id => 25450, # product = { id: 25450, name: 'dns' }
+ :customer_id => 423360, # customer = { id: 416942, email: joe@example.com }
+}
+
+puts "subscriptions *************** \n"
+subscriptions = Subscription.all
+puts subscriptions.size
+#puts subscriptions.first.response.body
+
+subscriptions[1].tap {|s| puts "id: #{s.object_id}" }.get
+ .tap { |s| puts "id: #{s.object_id}" }.reload
+ .tap { |s| puts "id: #{s.object_id}, state: #{s.cancellation_message}" }
+ .body(:cancellation_message => 'just a test').put
+ .tap { |s| puts "id: #{s.object_id}, state: #{s.cancellation_message}" }
+ .update_attributes(:cancellation_message => 'updated again').put
+ .tap { |s| puts "id: #{s.object_id}, state: #{s.cancellation_message}" }
+
+
+
+#subscription = Subscription.post attributes
+#puts subscription.attributes
+#subscription = subscriptions.each do |s|
+# puts s.attributes
+#end
+
+#subscription = Subscription.delete(415520)
+#puts subscription.response.response
+#puts subscription.attributes
Oops, something went wrong.

0 comments on commit 5017669

Please sign in to comment.