frulo 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/Manifest +5 -0
  2. data/README.rdoc +36 -0
  3. data/Rakefile +14 -0
  4. data/frulo.gemspec +33 -0
  5. data/init.rb +1 -0
  6. data/lib/frulo.rb +91 -0
  7. metadata +75 -0
@@ -0,0 +1,5 @@
1
+ Manifest
2
+ README.rdoc
3
+ Rakefile
4
+ init.rb
5
+ lib/frulo.rb
@@ -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 platform45-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 Platform45
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.2.1') do |p|
6
+ p.description = "API Wrapper to Frulo.co.za"
7
+ p.url = "http://github.com/platform45/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.2.1"
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{2010-02-16}
10
+ s.description = %q{API Wrapper to Frulo.co.za}
11
+ s.email = %q{ryan@platform45.com}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/frulo.rb"]
13
+ s.files = ["Manifest", "README.rdoc", "Rakefile", "init.rb", "lib/frulo.rb", "frulo.gemspec"]
14
+ s.homepage = %q{http://github.com/platform45/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.5}
19
+ s.summary = %q{API Wrapper to Frulo.co.za}
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
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'frulo'
@@ -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.co.za/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['subscriber'])
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,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: frulo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Oberholzer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-16 00:00:00 +02: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.co.za
26
+ email: ryan@platform45.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ - lib/frulo.rb
34
+ files:
35
+ - Manifest
36
+ - README.rdoc
37
+ - Rakefile
38
+ - init.rb
39
+ - lib/frulo.rb
40
+ - frulo.gemspec
41
+ has_rdoc: true
42
+ homepage: http://github.com/platform45/frulo-gem
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --line-numbers
48
+ - --inline-source
49
+ - --title
50
+ - Frulo
51
+ - --main
52
+ - README.rdoc
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "1.2"
66
+ version:
67
+ requirements: []
68
+
69
+ rubyforge_project: frulo
70
+ rubygems_version: 1.3.5
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: API Wrapper to Frulo.co.za
74
+ test_files: []
75
+