Skip to content
Browse files

Added ability to get Betas and Testers via REST API

  • Loading branch information...
1 parent 25fbd21 commit d704c6f9bae51027bd99f071a59cd8b62de54585 @jbritten jbritten committed May 3, 2009
Showing with 171 additions and 62 deletions.
  1. +4 −4 CONFIG
  2. +44 −7 README
  3. +0 −1 init.rb
  4. +0 −25 lib/helpers/feedback_helper.rb
  5. +6 −5 lib/helpers/invitation_helper.rb
  6. +117 −20 lib/prefinery.rb
View
8 CONFIG
@@ -3,13 +3,13 @@
Configuration
=============
-Sign up for a free account on http://www.prefinery.com and
-create a new web beta. Once you do this, you'll configure
-PrefineryBetaFu using the id of the beta you just created.
+Sign up for a free account on http://www.prefinery.com and create a new web beta. Once you
+do this, you'll configure Prefinery Ruby API as follows:
You should have something like this in config/initializers/prefinery.rb.
Prefinery.configure do |config|
config.subdomain = 'compulsivo'
- config.beta = '4'
+ config.api_key = '8cc4aae2a2fc0e1278a2079ea95b219e26f6beba'
end
+
View
51 README
@@ -1,45 +1,82 @@
-PrefineryBetaFu
-===============
+Prefinery Ruby API
+==================
+
+The official Ruby library for interacting with the Prefinery REST API.
Prefinery (http://www.prefinery.com) helps you launch a private beta in minutes.
Prefinery collects email addresses, generates invitation codes, and sends
invitations for your web beta. Your customers never leave your site and
e-mail invitations are sent from your address.
-PrefineryBetaFu gets Prefinery integrated into your Rails website in seconds.
+The Prefinery Ruby API gets Prefinery integrated into your Rails website in seconds.
Installation
============
- script/plugin install git://github.com/compulsivo/prefinery-beta-fu.git
+ script/plugin install git://github.com/compulsivo/prefinery-ruby-api.git
Configuration
=============
Sign up for a free account on http://www.prefinery.com and create a new web beta. Once you
-do this, you'll configure PrefineryBetaFu using the id of the beta you just created.
+do this, you'll configure Prefinery Ruby API as follows:
You should have something like this in config/initializers/prefinery.rb.
Prefinery.configure do |config|
config.subdomain = 'compulsivo'
- config.beta = '4'
+ config.api_key = '8cc4aae2a2fc0e1278a2079ea95b219e26f6beba'
end
+Documentation
+=============
+
+See lib/prefinery.rb
+
+Also, documentation on the REST API can be found at http://www.prefinery.com/api
+
Examples
========
+List testers
+
+ Prefinery::Tester.find(:all, :params => { :beta_id => 74 })
+ Prefinery::Tester.find(:all, :params => { :beta_id => 74, :email => "justin@prefinery.com" })
+
+Show a single tester
+
+ tester = Prefinery::Tester.find(1259, :params => { :beta_id => 74 })
+
+Creating a tester
+
+ tester = Prefinery::Tester.new(:beta_id => 74)
+ tester.email = 'justin@prefinery.com'
+ tester.profile = {:first_name = 'Justin', :last_name => 'Britten'}
+ tester.save
+
+Updating a tester
+
+ tester = Prefinery::Tester.find(1259, :params => { :beta_id => 74 })
+ tester.profile = {:city = 'Austin', :state => 'TX'}
+ tester.save
+
+
+Helpers
+=======
+
To include Prefinery's invitation javascript on your site's signup page:
-<%= prefinery_invitation_javascript %>
+<%= prefinery_invitation_javascript(:beta_id => 74) %>
To place a link on your site's signup page which will launch the Prefinery invitation widget:
<%= link_to_prefinery_invitation 'Sign up for the beta now!', '#' %>
+License
+=======
Copyright (c) 2009 Compulsivo, Inc. Released under the MIT license
View
1 init.rb
@@ -1,4 +1,3 @@
require 'prefinery'
require 'helpers/invitation_helper'
-require 'helpers/feedback_helper'
ActionView::Base.send :include, Prefinery::ViewHelper
View
25 lib/helpers/feedback_helper.rb
@@ -1,25 +0,0 @@
-module Prefinery
- module ViewHelper
- def prefinery_feedback_javascript
- <<-HTML
- <style type='text/css'>@import url('http://www.prefinery.com/stylesheets/widget.css');</style>
- <script src='http://www.prefinery.com/javascripts/widget.js' type='text/javascript'></script>
- <script type='text/javascript' charset='utf-8'>
- Prefinery.feedback("#{Prefinery.url}/comments/new?display=popup");
- </script>
- HTML
- end
-
- def prefinery_embed_feedback_form
- <<-HTML
- <iframe id='prefinery_iframe_inline' allowTransparency='true' width='100%' height='600' scrolling='no' frameborder='0' src="#{Prefinery.url}/comments/new?display=inline"></iframe>
- HTML
- end
-
- def link_to_prefinery_feedback(name, options = {}, html_options = {})
- html_options.merge!({:id => 'prefinery_feedback_link'})
- link_to name, options, html_options
- end
- end
-end
-
View
11 lib/helpers/invitation_helper.rb
@@ -1,18 +1,20 @@
module Prefinery
module ViewHelper
- def prefinery_invitation_javascript
+ def prefinery_invitation_javascript(options = {})
+ options.symbolize_keys!
<<-HTML
<style type='text/css'>@import url('http://www.prefinery.com/stylesheets/widget.css');</style>
<script src='http://www.prefinery.com/javascripts/widget.js' type='text/javascript'></script>
<script type='text/javascript' charset='utf-8'>
- Prefinery.invite("#{Prefinery.url}/testers/new?display=popup");
+ Prefinery.invite("#{Prefinery.url}/betas/#{options[:beta_id]}/testers/new?display=popup");
</script>
HTML
end
- def prefinery_embed_invitation_form
+ def prefinery_embed_invitation_form(options = {})
+ options.symbolize_keys!
<<-HTML
- <iframe id='prefinery_iframe_inline' allowTransparency='true' width='100%' height='600' scrolling='no' frameborder='0' src="#{Prefinery.url}/testers/new?display=inline"></iframe>
+ <iframe id='prefinery_iframe_inline' allowTransparency='true' width='100%' height='600' scrolling='no' frameborder='0' src="#{Prefinery.url}/betas/#{options[:beta_id]}/testers/new?display=inline"></iframe>
HTML
end
@@ -22,4 +24,3 @@ def link_to_prefinery_invitation(name, options = {}, html_options = {})
end
end
end
-
View
137 lib/prefinery.rb
@@ -1,45 +1,142 @@
+# Ruby lib for working with the Prefinery API's XML interface.
+#
+# You should have something like this in config/initializers/prefinery.rb.
+#
+# Prefinery.configure do |config|
+# config.subdomain = 'compulsivo'
+# config.secure = false
+# config.api_key = 8cc4aae2a2fc0e1278a2079ea95b219e26f6beba
+# end
+#
+#
+# Read the docs at:
+# http://www.prefinery.com/api
+#
+
require 'rubygems'
+require 'activesupport'
+require 'activeresource'
module Prefinery
class << self
- attr_accessor :subdomain, :host, :port, :secure, :beta
+ attr_accessor :subdomain, :host, :port, :secure, :api_key, :host_format
+ def configure
+ yield self
+ resources.each do |klass|
+ klass.site = klass.site_format % (host_format % [protocol, host, port])
+ end
+ end
+
def subdomain
@subdomain
end
+ def host
+ @host ||= "#{subdomain}.prefinery.com"
+ end
+
def port
@port || (secure ? 443 : 80)
end
- def host
- @host ||= "#{subdomain}.prefinery.com"
+ def api_key
+ @api_key
end
- def beta
- @beta
+ def protocol
+ secure ? "https" : "http"
end
-
- # Call this method to modify defaults in your initializers.
- #
- # Prefinery.configure do |config|
- # config.subdomain = 'compulsivo'
- # config.beta = '1'
- # config.secure = false
- # end
- def configure
- yield self
+
+ def url
+ URI.parse("#{protocol}://#{host}:#{port}")
end
- def protocol #:nodoc:
- secure ? "https" : "http"
+ def resources
+ @resources ||= []
end
- def url #:nodoc:
- URI.parse("#{protocol}://#{host}:#{port}/betas/#{beta}")
+ end
+ self.host_format = '%s://%s:%s/api/v1'
+
+ class Base < ActiveResource::Base
+ def self.inherited(base)
+ Prefinery.resources << base
+ class << base
+ attr_accessor :site_format
+ end
+ base.site_format = '%s'
+ super
+ end
+ end
+
+ # List betas
+ #
+ # Prefinery::Beta.find(:all)
+ #
+ # Show a single beta
+ #
+ # beta = Prefinery::Beta.find(1)
+ #
+ # List testers
+ #
+ # beta.testers
+ #
+ # Find a tester by email
+ #
+ # beta.testers(:email => 'justin@prefinery.com')
+ #
+ class Beta < Base
+ def testers(options = {})
+ Tester.find(:all, :params => options.update(:beta_id => id))
end
+ end
+
+ # List testers
+ #
+ # Prefinery::Tester.find(:all, :params => { :beta_id => 74 })
+ # Prefinery::Tester.find(:all, :params => { :beta_id => 74, :email => "justin@prefinery.com" })
+ #
+ # Show a single tester
+ #
+ # tester = Prefinery::Tester.find(1259, :params => { :beta_id => 74 })
+ #
+ # Creating a tester
+ #
+ # tester = Prefinery::Tester.new(:beta_id => 74)
+ # tester.email = 'justin@prefinery.com'
+ # tester.status = 'active'
+ # tester.invitation_code = 'TECHCRUNCH'
+ # tester.profile = {:first_name = 'Justin', :last_name => 'Britten'}
+ # tester.save
+ #
+ # Updating a tester
+ #
+ # tester = Prefinery::Tester.find(1259, :params => { :beta_id => 74 })
+ # tester.profile = {:city = 'Austin', :state => 'TX'}
+ # tester.save
+ #
+ # Deleting a tester
+ #
+ # tester = Prefinery::Tester.find(1259, :params => { :beta_id => 74 })
+ # tester.destroy
+ #
+ class Tester < Base
+ site_format << '/betas/:beta_id'
+ def profile=(profile_attributes)
+ attributes['profile'] = profile_attributes
+ end
end
-
+
end
+
+module ActiveResource
+ class Connection
+ private
+ def authorization_header
+ (Prefinery.api_key ? { 'Authorization' => 'Basic ' + ["#{Prefinery.api_key}:X"].pack('m').delete("\r\n") } : {})
+ end
+ end
+end

0 comments on commit d704c6f

Please sign in to comment.
Something went wrong with that request. Please try again.