ryanp45-frulo 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/README.rdoc +36 -0
  2. data/Rakefile +14 -0
  3. data/frulo.gemspec +33 -0
  4. data/lib/frulo.rb +91 -0
  5. metadata +72 -0
@@ -0,0 +1,36 @@
1
+ = Frulo API Wrapper
2
+
3
+ This is an API wrapper for frulo.com.
4
+
5
+ == Install
6
+
7
+ gem install ryanp45-frulo --source http://gems.github.com
8
+
9
+ == Usage
10
+
11
+ This gem will simplify communication with frulo.com, and help with integration process needed to manage billing on your system. Please check out API documentation for more information.
12
+
13
+ == License
14
+
15
+ Copyright (c) 2008 Ryan Bates
16
+
17
+ Permission is hereby granted, free of charge, to any person obtaining
18
+ a copy of this software and associated documentation files (the
19
+ "Software"), to deal in the Software without restriction, including
20
+ without limitation the rights to use, copy, modify, merge, publish,
21
+ distribute, sublicense, and/or sell copies of the Software, and to
22
+ permit persons to whom the Software is furnished to do so, subject to
23
+ the following conditions:
24
+
25
+ The above copyright notice and this permission notice shall be
26
+ included in all copies or substantial portions of the Software.
27
+
28
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
+
36
+
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('frulo', '0.1.0') do |p|
6
+ p.description = "API Wrapper to Frulo.com"
7
+ p.url = "http://github.com/ryanp45/frulo-gem"
8
+ p.author = "Ryan Oberholzer"
9
+ p.email = "ryan@platform45.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = ["httparty"]
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{frulo}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Ryan Oberholzer"]
9
+ s.date = %q{2009-08-20}
10
+ s.description = %q{API Wrapper to Frulo.com}
11
+ s.email = %q{ryan@platform45.com}
12
+ s.extra_rdoc_files = ["lib/frulo.rb", "README.rdoc"]
13
+ s.files = ["lib/frulo.rb", "Rakefile", "README.rdoc", "frulo.gemspec"]
14
+ s.homepage = %q{http://github.com/ryanp45/frulo-gem}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Frulo", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{frulo}
18
+ s.rubygems_version = %q{1.3.4}
19
+ s.summary = %q{API Wrapper to Frulo.com}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ s.add_development_dependency(%q<httparty>, [">= 0"])
27
+ else
28
+ s.add_dependency(%q<httparty>, [">= 0"])
29
+ end
30
+ else
31
+ s.add_dependency(%q<httparty>, [">= 0"])
32
+ end
33
+ end
@@ -0,0 +1,91 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+
4
+ module Frulo
5
+ include HTTParty
6
+ headers 'Accept' => 'text/xml'
7
+ headers 'Content-Type' => 'text/xml'
8
+ format :xml
9
+
10
+ def self.configure(site_name, token)
11
+ base_uri "http://frulo.com/v1/#{site_name}"
12
+ @site_name = site_name
13
+ default_params :user_credentials => token
14
+ end
15
+
16
+ def self.to_xml_params(hash) # :nodoc:
17
+ hash.collect do |key, value|
18
+ tag = key.to_s.tr('_', '-')
19
+ result = "<#{tag}>"
20
+ if value.is_a?(Hash)
21
+ result << to_xml_params(value)
22
+ else
23
+ result << value.to_s
24
+ end
25
+ result << "</#{tag}>"
26
+ result
27
+ end.join('')
28
+ end
29
+
30
+ class Resource
31
+ def initialize(data)
32
+ @data = data
33
+ end
34
+
35
+ def id
36
+ @data["id"]
37
+ end
38
+
39
+ def method_missing(method, *args, &block)
40
+ if method.to_s =~ /\?$/
41
+ send(method.to_s[0..-2])
42
+ elsif @data.include?(method.to_s)
43
+ @data[method.to_s]
44
+ else
45
+ super
46
+ end
47
+ end
48
+ end
49
+
50
+ class Subscriber < Resource
51
+ def self.all
52
+ request = Frulo.get("/subscribers.xml")
53
+ request['subscribers'].collect{|data| Subscriber.new(data)}
54
+ end
55
+
56
+ def self.find(id)
57
+ request = Frulo.get("/subscriber/#{id}.xml")
58
+ request.nil? ? nil : Subscriber.new(request['hash'])
59
+ end
60
+
61
+ def id
62
+ subscriber['customer_id']
63
+ end
64
+
65
+ def extend_subscription!
66
+ request = Frulo.put("/subscriber/#{self.id}/extend_subscription.xml")
67
+ request.code == 200 ? true : false
68
+ end
69
+
70
+ def update_plan(plan_id)
71
+ request = Frulo.post("/subscriber/#{self.id}/update_plan.xml", :body => {:plan => {:id => plan_id }})
72
+ request.code == 200 ? true : false
73
+ end
74
+
75
+ def trial?
76
+ subscription['state'].to_s == 'trial'
77
+ end
78
+ end
79
+
80
+ class Plan < Resource
81
+ def self.all
82
+ request = Frulo.get("/plans.xml")
83
+ request['plans'].collect{|data| Plan.new(data)}
84
+ end
85
+
86
+ def self.find(id)
87
+ request = all
88
+ request.detect{ |p| p.id.to_s == id.to_s }
89
+ end
90
+ end
91
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ryanp45-frulo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Oberholzer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-20 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: API Wrapper to Frulo.com
26
+ email: ryan@platform45.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - lib/frulo.rb
33
+ - README.rdoc
34
+ files:
35
+ - lib/frulo.rb
36
+ - Rakefile
37
+ - README.rdoc
38
+ - frulo.gemspec
39
+ has_rdoc: false
40
+ homepage: http://github.com/ryanp45/frulo-gem
41
+ licenses:
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --line-numbers
45
+ - --inline-source
46
+ - --title
47
+ - Frulo
48
+ - --main
49
+ - README.rdoc
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "1.2"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project: frulo
67
+ rubygems_version: 1.3.5
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: API Wrapper to Frulo.com
71
+ test_files: []
72
+