zenbe-flareshow 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Flareshow.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{flareshow}
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Will Bailey"]
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
34
34
  "lib/membership.rb",
35
35
  "lib/post.rb",
36
36
  "lib/resource.rb",
37
+ "lib/searchable.rb",
37
38
  "lib/server.rb",
38
39
  "lib/service.rb",
39
40
  "lib/user.rb",
data/README.txt CHANGED
@@ -6,4 +6,65 @@
6
6
  \ \_\ /\____\ \__/.\_\\ \_\\ \____\/\____/ \ \_\ \_\ \____/\ \___x___/'
7
7
  \/_/ \/____/\/__/\/_/ \/_/ \/____/\/___/ \/_/\/_/\/___/ \/__//__/
8
8
 
9
- ~ Client Library For the Zenbe Shareflow API
9
+ ~ Client Library For the Zenbe Shareflow API
10
+
11
+ == OVERVIEW
12
+
13
+ Flareshow provides a ruby wrapper around the shareflow json rpc wire protocol. For more information about the Shareflow API see:
14
+ <Shareflow API Docs Link>
15
+
16
+ == AUTHENTICATION
17
+
18
+ All actions in Flareshow require authenticationFlareshow can automatically authenticate you against your shareflow server. Just create a YAML formatted .flareshowrc file in your home directory with the following keys
19
+
20
+ subdomain : demo.zenbe.com
21
+ login : demo
22
+ password : password
23
+
24
+ To authenticate manually do the following:
25
+
26
+ Flareshow::Service.configure(<subdomain>)
27
+ Flareshow.authenticate(<login>, <password>)
28
+
29
+ == USAGE
30
+
31
+ Once you've authenticated you can choose to use either interact directly with the Flareshow::Service or use the Flareshow::Resource domain models which encapsulate the domain logic of Shareflow providing a friendlier development environment.
32
+
33
+ == EXAMPLES
34
+
35
+ = Reading Posts
36
+
37
+ # the following code will read all posts on the server in a loop
38
+
39
+ per_request = 30 # 30 is the default returned by the server -- max is 100
40
+ results = []
41
+ loop do
42
+ offset ||= 0
43
+ results << Post.find(:offset => offset, :limit => per_request)
44
+ offset += per_request
45
+ end
46
+
47
+ = Upload a file to a Post
48
+ p=Post.new()
49
+ p.save
50
+ p.create_file("/path/to/your/file")
51
+
52
+ = Searching for a post
53
+
54
+ # posts, files, comments include the searchable mixin
55
+ # and can be searched using full text search capabilities
56
+ # on the server
57
+ results = Post.search("some keywords")
58
+
59
+ = deleting a post or comment
60
+ Post.find(:limit => 1).first.destroy
61
+ Comment.find(:limit => 1).first.destroy
62
+
63
+ = Renaming a flow
64
+ f=Flow.find_by_name('test')
65
+ f.name = 'a different name'
66
+ f.save
67
+
68
+ == Caching
69
+
70
+ If you choose to use the Flareshow::Resource objects to manage requests through the Service a caching layer is built in. Currently this cache is in memory only; however, the API is designed to allow developers to plugin alternate caches as desired. For example if you wanted to persist shareflow data in a sql lite database you just need to create a SQLLite cache class implementing the Flareshow cache interface.
data/TODO CHANGED
@@ -1,4 +1,5 @@
1
1
  TODO:
2
+ shareflow api docs
2
3
  write tests with Fakeweb
3
4
  flesh out more resource methods
4
5
  make post requests with embedded file attachments respond with the file attachments for now...later we need to allow the creation of files in the same way as posts as flat
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
data/lib/cache.rb CHANGED
@@ -7,20 +7,25 @@ class Flareshow::CacheManager
7
7
  def assimilate_resources(data)
8
8
  # process each resource key and generate a new object
9
9
  # or merge the object data with an existing object
10
- data.each do |resource_pair|
10
+ data.inject({}) do |memo,resource_pair|
11
11
  resource_key, resources = resource_pair[0], resource_pair[1]
12
+
13
+ fs_resource_array = memo[resource_key] ||= []
14
+
12
15
  klass = Kernel.const_get(Flareshow::ResourceToClassMap[resource_key])
13
- next unless klass
14
- resources = resources.map do |resource_data|
15
- item = cache.get_resource(resource_key, resource_data["id"])
16
- if item
17
- item.update(resource_data, :server)
18
- else
19
- item = klass.new(resource_data, :server)
16
+ if klass
17
+ resources.each do |resource_data|
18
+ item = cache.get_resource(resource_key, resource_data["id"])
19
+ if item
20
+ item.update(resource_data, :server)
21
+ else
22
+ item = klass.new(resource_data, :server)
23
+ end
24
+ cache.set_resource(resource_key, item.id, item)
25
+ fs_resource_array << item
20
26
  end
21
- cache.set_resource(resource_key, item.id, item)
22
- item
23
27
  end
28
+ memo
24
29
  end
25
30
  end
26
31
 
@@ -47,6 +52,10 @@ class Flareshow::Cache
47
52
  resource_cache(resource_key)[id] = object
48
53
  end
49
54
 
55
+ def list_resource(resource_key)
56
+ resource_cache(resource_key)
57
+ end
58
+
50
59
  # remove all cached objects
51
60
  def flush
52
61
  data = {}
@@ -58,6 +67,7 @@ class Flareshow::Cache
58
67
  end
59
68
 
60
69
  private
70
+ # data store for the cache
61
71
  def data
62
72
  @cache ||= {}
63
73
  end
data/lib/comment.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  class Comment < Flareshow::Resource
2
2
 
3
+ extend Flareshow::Searchable
4
+
3
5
  # permalink to this comment
4
6
  def permalink(mobile=false)
5
7
  if mobile
@@ -1,5 +1,7 @@
1
1
  class FileAttachment < Flareshow::Resource
2
2
 
3
+ extend Flareshow::Searchable
4
+
3
5
  # =================
4
6
  # = Class Methods =
5
7
  # =================
data/lib/flareshow.rb CHANGED
@@ -39,6 +39,7 @@ end
39
39
  require File.join(ROOT, 'service')
40
40
  require File.join(ROOT, 'resource')
41
41
  require File.join(ROOT, 'cache')
42
+ require File.join(ROOT, 'searchable')
42
43
 
43
44
  # logging
44
45
  DEFAULT_LOGGER = Logger.new(STDOUT) unless defined?(DEFAULT_LOGGER)
data/lib/flow.rb CHANGED
@@ -13,9 +13,9 @@ class Flow < Flareshow::Resource
13
13
  # permalink for this flow
14
14
  def permalink(mobile=false)
15
15
  if mobile
16
- "http://#{Flareshow::Base.server.host}/#{Flareshow::Base.server.domain}/shareflow/mobile/flows/#{id}"
16
+ "http://#{Flareshow::Service.server.host}/#{Flareshow::Service.server.domain}/shareflow/mobile/flows/#{id}"
17
17
  else
18
- "http://#{Flareshow::Base.server.host}/#{Flareshow::Base.server.domain}/shareflow/c/#{id}"
18
+ "http://#{Flareshow::Service.server.host}/#{Flareshow::Service.server.domain}/shareflow/c/#{id}"
19
19
  end
20
20
  end
21
21
 
data/lib/post.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  class Post < Flareshow::Resource
2
2
 
3
+ extend Flareshow::Searchable
4
+
3
5
  # permalink to this post
4
6
  def permalink(mobile=false)
5
7
  if mobile
6
- "http://#{Flareshow::Base.server.host}/#{Flareshow::Base.server.domain}/shareflow/mobile/post/#{id}"
8
+ "http://#{Flareshow::Service.server.host}/#{Flareshow::Service.server.domain}/shareflow/mobile/post/#{id}"
7
9
  else
8
- "http://#{Flareshow::Base.server.host}/#{Flareshow::Base.server.domain}/shareflow/p/#{id}"
10
+ "http://#{Flareshow::Service.server.host}/#{Flareshow::Service.server.domain}/shareflow/p/#{id}"
9
11
  end
10
12
  end
11
13
 
data/lib/resource.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  class Flareshow::Resource
2
2
 
3
3
  class << self
4
+ attr_accessor :read_only, :attr_accessible
5
+
4
6
  # return the resource key for this resource
5
7
  def resource_key
6
8
  Flareshow::ClassToResourceMap[self.name]
@@ -26,10 +28,9 @@ class Flareshow::Resource
26
28
  # the keyed resources for the model performing the query
27
29
  def find(params={})
28
30
  response = Flareshow::Service.query({resource_key => params})
29
- cache_response(response)
30
- (response["resources"] || {})[resource_key]
31
+ (cache_response(response) || {})[resource_key]
31
32
  end
32
-
33
+
33
34
  # create a resource local and sync it to the server
34
35
  def create(params={})
35
36
  new(params).save
@@ -80,7 +81,7 @@ class Flareshow::Resource
80
81
 
81
82
  # destroy the resource on the server
82
83
  def destroy
83
- response = self.class.commit({resource_key => [{"id" => id, "_removed" => true}]})
84
+ response = Flareshow::Service.commit({resource_key => [{"id" => id, "_removed" => true}]})
84
85
  cache_response(response)
85
86
  mark_destroyed!
86
87
  self
@@ -93,6 +94,7 @@ class Flareshow::Resource
93
94
 
94
95
  private
95
96
 
97
+ # clear the element of the cache
96
98
  def mark_destroyed!
97
99
  self.freeze
98
100
  self._removed=true
data/lib/searchable.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Flareshow
2
+ module Searchable
3
+
4
+ def search(keywords)
5
+ self.find({:keywords => keywords})
6
+ end
7
+
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zenbe-flareshow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Bailey
@@ -99,6 +99,7 @@ files:
99
99
  - lib/membership.rb
100
100
  - lib/post.rb
101
101
  - lib/resource.rb
102
+ - lib/searchable.rb
102
103
  - lib/server.rb
103
104
  - lib/service.rb
104
105
  - lib/user.rb