ruby-satisfaction 0.2.0 → 0.3.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.
data/lib/satisfaction.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'satisfaction/external_dependencies'
2
-
2
+ module Sfn
3
+ end
3
4
  class Satisfaction
4
5
  # ==================
5
6
  # = Core Utilities =
@@ -42,8 +43,8 @@ class Satisfaction
42
43
  :access_token_url => 'http://getsatisfaction.com/api/access_token',
43
44
  :authorize_url => 'http://getsatisfaction.com/api/authorize',
44
45
  })
45
- @loader = Satisfaction::Loader.new
46
- @identity_map = Satisfaction::IdentityMap.new
46
+ @loader = Sfn::Loader.new
47
+ @identity_map = Sfn::IdentityMap.new
47
48
 
48
49
  has_many :companies, :url => '/companies'
49
50
  has_many :people, :url => '/people'
@@ -59,7 +60,7 @@ class Satisfaction
59
60
 
60
61
  def me
61
62
  me = satisfaction.identity_map.get_record(Me, 'me') do
62
- Me.new('me', satisfaction)
63
+ Sfn::Me.new('me', satisfaction)
63
64
  end
64
65
 
65
66
  if me.loaded?
@@ -90,7 +91,9 @@ class Satisfaction
90
91
  end
91
92
 
92
93
  def request_token
93
- response = CGI.parse(@loader.get("#{options[:request_token_url]}", :force => true, :consumer => @consumer, :token => nil))
94
+ result, body = *@loader.get("#{options[:request_token_url]}", :force => true, :consumer => @consumer, :token => nil)
95
+ raise "Could not retrieve request token" unless result == :ok
96
+ response = CGI.parse(body)
94
97
  OAuth::Token.new(response["oauth_token"], response["oauth_token_secret"])
95
98
  end
96
99
 
@@ -99,7 +102,9 @@ class Satisfaction
99
102
  end
100
103
 
101
104
  def access_token(token)
102
- response = CGI.parse(@loader.get("#{options[:access_token_url]}", :force => true, :consumer => @consumer, :token => token))
105
+ result, body = *@loader.get("#{options[:access_token_url]}", :force => true, :consumer => @consumer, :token => token)
106
+ raise "Could not retrieve access token" unless result == :ok
107
+ response = CGI.parse(body)
103
108
  OAuth::Token.new(response["oauth_token"], response["oauth_token_secret"])
104
109
  end
105
110
 
@@ -1,15 +1,15 @@
1
1
  module Associations
2
2
  def has_many(resource, options={})
3
- class_name = options[:class_name] || resource.to_s.classify
3
+ class_name = options[:class_name] || "Sfn::#{resource.to_s.classify}"
4
4
  eval <<-EOS
5
5
  def #{resource}
6
- @#{resource} ||= ResourceCollection.new(#{class_name}, self.satisfaction, '#{options[:url]}')
6
+ @#{resource} ||= Sfn::ResourceCollection.new(#{class_name}, self.satisfaction, '#{options[:url]}')
7
7
  end
8
8
  EOS
9
9
  end
10
10
 
11
11
  def belongs_to(resource, options={})
12
- class_name = options[:class_name] || resource.to_s.classify
12
+ class_name = options[:class_name] || "Sfn::#{resource.to_s.classify}"
13
13
  parent_id = options[:parent_attribute] || "#{resource}_id"
14
14
  eval <<-EOS
15
15
  def #{resource}
@@ -1,11 +1,11 @@
1
- class Satisfaction::Loader::HashCache
1
+ class Sfn::Loader::HashCache
2
2
  def initialize
3
3
  @cached_responses = {}
4
4
  end
5
5
 
6
6
  def put(url, response)
7
7
  return nil if response["ETag"].blank?
8
- @cached_responses[url.to_s] = Satisfaction::Loader::CacheRecord.new(url, response["ETag"], response.body)
8
+ @cached_responses[url.to_s] = Sfn::Loader::CacheRecord.new(url, response["ETag"], response.body)
9
9
  end
10
10
 
11
11
  def get(url)
@@ -1,5 +1,5 @@
1
1
 
2
- class Satisfaction::Loader::MemcacheCache
2
+ class Sfn::Loader::MemcacheCache
3
3
  def initialize(options = {})
4
4
  options = options.reverse_merge({:servers => ['127.0.0.1:11211'], :namespace => 'satisfaction', })
5
5
  @m = MemCache.new(options.delete(:servers), options)
@@ -8,7 +8,7 @@ class Satisfaction::Loader::MemcacheCache
8
8
  def put(url, response)
9
9
  return nil if response["ETag"].blank?
10
10
 
11
- @m[url.to_s] = Loader::CacheRecord.new(url, response["ETag"], response.body)
11
+ @m[url.to_s] = Sfn::Loader::CacheRecord.new(url, response["ETag"], response.body)
12
12
  end
13
13
 
14
14
  def get(url)
@@ -1,4 +1,4 @@
1
- class Company < Resource
1
+ class Sfn::Company < Sfn::Resource
2
2
 
3
3
  attributes :domain, :name, :logo, :description
4
4
 
@@ -10,7 +10,7 @@ class Company < Resource
10
10
  has_many :people, :url => "#{path}/people"
11
11
  has_many :topics, :url => "#{path}/topics"
12
12
  has_many :products, :url => "#{path}/products"
13
- has_many :employees, :url => "#{path}/employees", :class_name => 'Person'
13
+ has_many :employees, :url => "#{path}/employees", :class_name => 'Sfn::Person'
14
14
  has_many :tags, :url => "#{path}/tags"
15
15
 
16
16
  end
@@ -1,4 +1,4 @@
1
- class Satisfaction::HasSatisfaction
1
+ class Sfn::HasSatisfaction
2
2
  attr_reader :satisfaction
3
3
 
4
4
  def initialize(satisfaction)
@@ -1,4 +1,4 @@
1
- class Satisfaction::IdentityMap
1
+ class Sfn::IdentityMap
2
2
  attr_reader :records, :pages
3
3
 
4
4
  def initialize
@@ -2,7 +2,7 @@ require 'net/http'
2
2
  require 'uri'
3
3
 
4
4
 
5
- class Satisfaction::Loader
5
+ class Sfn::Loader
6
6
  require 'satisfaction/cache/hash'
7
7
  require 'satisfaction/cache/memcache'
8
8
 
@@ -34,7 +34,7 @@ class Satisfaction::Loader
34
34
  end
35
35
 
36
36
  http = Net::HTTP.new(uri.host, uri.port)
37
- add_authentication(request, options)
37
+ add_authentication(request, http, options)
38
38
  response = execute(http, request)
39
39
 
40
40
  case response
@@ -73,7 +73,7 @@ class Satisfaction::Loader
73
73
  request.set_form_data(form)
74
74
 
75
75
  http = Net::HTTP.new(uri.host, uri.port)
76
- add_authentication(request, options)
76
+ add_authentication(request, http, options)
77
77
  response = execute(http, request)
78
78
 
79
79
  case response
@@ -104,7 +104,7 @@ class Satisfaction::Loader
104
104
  end
105
105
  end
106
106
 
107
- def add_authentication(request, options)
107
+ def add_authentication(request, http, options)
108
108
  if options[:user]
109
109
  request.basic_auth(options[:user], options[:password])
110
110
  elsif options[:consumer]
@@ -1,4 +1,4 @@
1
- class Person < Resource
1
+ class Sfn::Person < Sfn::Resource
2
2
  attributes :name, :id, :photo, :tagline
3
3
 
4
4
  def path
@@ -8,11 +8,11 @@ class Person < Resource
8
8
  def setup_associations
9
9
  has_many :replies, :url => "#{path}/replies"
10
10
  has_many :topics, :url => "#{path}/topics"
11
- has_many :followed_topics, :url => "#{path}/followed/topics", :class_name => 'Topic'
11
+ has_many :followed_topics, :url => "#{path}/followed/topics", :class_name => 'Sfn::Topic'
12
12
  end
13
13
  end
14
14
 
15
- class Me < Person
15
+ class Me < Sfn::Person
16
16
  def path
17
17
  loaded? ? super : "/me"
18
18
  end
@@ -1,4 +1,4 @@
1
- class Product < Resource
1
+ class Sfn::Product < Sfn::Resource
2
2
  attributes :name, :url, :image, :description
3
3
  attribute :last_active_at, :type => Time
4
4
  attribute :created_at, :type => Time
@@ -1,7 +1,7 @@
1
- class Reply < Resource
1
+ class Sfn::Reply < Sfn::Resource
2
2
  attributes :content, :star_count, :topic_id
3
3
  attribute :created_at, :type => Time
4
- attribute :author, :type => Person
4
+ attribute :author, :type => Sfn::Person
5
5
 
6
6
  def path
7
7
  "/replies/#{id}"
@@ -1,11 +1,11 @@
1
1
  require 'forwardable'
2
2
 
3
- class Resource < Satisfaction::HasSatisfaction
3
+ class Sfn::Resource < Sfn::HasSatisfaction
4
4
  require 'satisfaction/resource/attributes'
5
5
  include ::Associations
6
6
  include Attributes
7
7
  attr_reader :id
8
- include Satisfaction::Util
8
+ include Sfn::Util
9
9
 
10
10
 
11
11
  def initialize(id, satisfaction)
@@ -56,15 +56,19 @@ class Resource < Satisfaction::HasSatisfaction
56
56
  end
57
57
 
58
58
  def inspect
59
- "<#{self.class.name} #{attributes.map{|k,v| "#{k}: #{v}"}.join(' ') if !attributes.nil?}>"
59
+ if loaded?
60
+ "<#{self.class.name} #{attributes.map{|k,v| "#{k}: #{v}"}.join(' ') if !attributes.nil?}>"
61
+ else
62
+ "<#{self.class.name} #{path} UNLOADED>"
63
+ end
60
64
  end
61
65
 
62
66
  end
63
67
 
64
- class ResourceCollection < Satisfaction::HasSatisfaction
68
+ class Sfn::ResourceCollection < Sfn::HasSatisfaction
65
69
  attr_reader :klass
66
70
  attr_reader :path
67
- include Satisfaction::Util
71
+ include Sfn::Util
68
72
 
69
73
  def initialize(klass, satisfaction, path)
70
74
  super satisfaction
@@ -73,7 +77,7 @@ class ResourceCollection < Satisfaction::HasSatisfaction
73
77
  end
74
78
 
75
79
  def page(number, options={})
76
- Page.new(self, number, options)
80
+ Sfn::Page.new(self, number, options)
77
81
  end
78
82
 
79
83
  def get(id, options={})
@@ -112,7 +116,7 @@ class ResourceCollection < Satisfaction::HasSatisfaction
112
116
 
113
117
  end
114
118
 
115
- class Page < Satisfaction::HasSatisfaction
119
+ class Sfn::Page < Sfn::HasSatisfaction
116
120
  attr_reader :total
117
121
  attr_reader :collection
118
122
 
@@ -1,4 +1,4 @@
1
- module Resource::Attributes
1
+ module Sfn::Resource::Attributes
2
2
  def self.included(base)
3
3
  base.class_eval do
4
4
  extend ClassMethods
@@ -54,7 +54,7 @@ class Time
54
54
  end
55
55
  end
56
56
 
57
- class Resource
57
+ class Sfn::Resource
58
58
  def self.decode_sfn(value, satisfaction)
59
59
  case value
60
60
  when Hash
@@ -1,4 +1,4 @@
1
- class Tag < Resource
1
+ class Sfn::Tag < Sfn::Resource
2
2
  attributes :name
3
3
 
4
4
  def path
@@ -1,8 +1,8 @@
1
- class Topic < Resource
2
- attributes :subject, :style, :content, :reply_count, :follower_count, :company_id
1
+ class Sfn::Topic < Sfn::Resource
2
+ attributes :subject, :style, :content, :reply_count, :follower_count, :company_id, :at_sfn
3
3
  attribute :last_active_at, :type => Time
4
4
  attribute :created_at, :type => Time
5
- attribute :author, :type => Person
5
+ attribute :author, :type => Sfn::Person
6
6
 
7
7
  def path
8
8
  "/topics/#{@id}"
@@ -1,4 +1,4 @@
1
- module Satisfaction::Util
1
+ module Sfn::Util
2
2
  def requestify(parameters, prefix=nil)
3
3
  parameters.inject({}) do |results, kv|
4
4
  if Hash === kv.last
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-satisfaction
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Fleckenstein
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-15 00:00:00 -08:00
12
+ date: 2009-07-06 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -23,6 +24,7 @@ dependencies:
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: oauth
27
+ type: :runtime
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
@@ -32,6 +34,7 @@ dependencies:
32
34
  version:
33
35
  - !ruby/object:Gem::Dependency
34
36
  name: memcache-client
37
+ type: :runtime
35
38
  version_requirement:
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
@@ -41,6 +44,7 @@ dependencies:
41
44
  version:
42
45
  - !ruby/object:Gem::Dependency
43
46
  name: activesupport
47
+ type: :runtime
44
48
  version_requirement:
45
49
  version_requirements: !ruby/object:Gem::Requirement
46
50
  requirements:
@@ -57,9 +61,7 @@ extensions: []
57
61
  extra_rdoc_files: []
58
62
 
59
63
  files:
60
- - lib/satisfaction
61
64
  - lib/satisfaction/associations.rb
62
- - lib/satisfaction/cache
63
65
  - lib/satisfaction/cache/hash.rb
64
66
  - lib/satisfaction/cache/memcache.rb
65
67
  - lib/satisfaction/company.rb
@@ -70,7 +72,6 @@ files:
70
72
  - lib/satisfaction/person.rb
71
73
  - lib/satisfaction/product.rb
72
74
  - lib/satisfaction/reply.rb
73
- - lib/satisfaction/resource
74
75
  - lib/satisfaction/resource/attributes.rb
75
76
  - lib/satisfaction/resource.rb
76
77
  - lib/satisfaction/tag.rb
@@ -78,8 +79,10 @@ files:
78
79
  - lib/satisfaction/util.rb
79
80
  - lib/satisfaction/version.rb
80
81
  - lib/satisfaction.rb
81
- has_rdoc: false
82
+ has_rdoc: true
82
83
  homepage: http://nullstyle.com
84
+ licenses: []
85
+
83
86
  post_install_message:
84
87
  rdoc_options: []
85
88
 
@@ -100,9 +103,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
103
  requirements: []
101
104
 
102
105
  rubyforge_project:
103
- rubygems_version: 1.0.1
106
+ rubygems_version: 1.3.4
104
107
  signing_key:
105
- specification_version: 2
108
+ specification_version: 3
106
109
  summary: Helper gem for the getsatisfaction.com API
107
110
  test_files: []
108
111