towsta 0.4.1 → 1.0.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.
@@ -0,0 +1,31 @@
1
+ require 'dalli'
2
+ require 'digest/md5'
3
+
4
+ set :cache, Dalli::Client.new
5
+
6
+ module Towsta
7
+
8
+ class Memory
9
+
10
+ def self.recover params
11
+ md5 = Memory.md5(params)
12
+ if settings.cache.get(md5)
13
+ puts 'Using cache to Towst'
14
+ Towsta::Synchronizer.new :path => $towsta_path, :cache => settings.cache.get(md5)
15
+ else
16
+ puts 'Creating cache'
17
+ syn = Towsta::Synchronizer.new :secret => $towsta_secret, :path => $towsta_path, :params => params
18
+ settings.cache.set(md5,syn.json)
19
+ end
20
+ end
21
+
22
+ def self.flush
23
+ settings.cache.flush
24
+ end
25
+
26
+ def self.md5 params
27
+ digest = Digest::MD5.hexdigest(params.inspect.to_s)
28
+ end
29
+
30
+ end
31
+ end
@@ -6,17 +6,22 @@ require 'time'
6
6
  module Towsta
7
7
  class Synchronizer
8
8
 
9
- attr_accessor :secret, :path, :json, :params
9
+ attr_accessor :secret, :path, :json, :params, :cache
10
10
 
11
11
  def initialize args
12
12
  @secret = args[:secret]
13
13
  @path = "#{args[:path]}.json"
14
14
  @params = args[:params]
15
+ @cache = args[:cache]
15
16
  synchronize ? backup : find_old
16
17
  puts just_do_it ? 'Ready to Towst!' : 'Unable to keep Towsting!'
17
18
  end
18
19
 
19
20
  def synchronize
21
+ unless @cache.nil?
22
+ @json = @cache
23
+ return true
24
+ end
20
25
  unless @secret
21
26
  puts 'you cant synchronize without a secret...'
22
27
  return false
@@ -79,7 +84,7 @@ module Towsta
79
84
  end
80
85
  end
81
86
  true
82
- end
87
+ end
83
88
 
84
89
  def self.callback json
85
90
  json = JSON.parse json, :symbolize_names => true
@@ -1,3 +1,3 @@
1
1
  module Towsta
2
- VERSION = "0.4.1"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/towsta.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  #require File.expand_path('../towsta/tree', __FILE__)
2
2
  require File.expand_path('../towsta/vertical', __FILE__)
3
3
  require File.expand_path('../towsta/synchronizer', __FILE__)
4
+ require File.expand_path('../towsta/memory', __FILE__)
4
5
 
5
6
  module Towsta
6
7
  end
@@ -9,5 +10,10 @@ def sync_with_towsta params=nil
9
10
  params ||= {} if $towsta_sync
10
11
  $towsta_sync ||= {}
11
12
  params = $towsta_sync.merge(params) if params
13
+ return Towsta::Memory.recover params if $towsta_cache
12
14
  Towsta::Synchronizer.new :secret => $towsta_secret, :path => $towsta_path, :params => params
13
15
  end
16
+
17
+ def clear_sync
18
+ Towsta::Memory.flush
19
+ end
data/towsta.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.add_dependency("json")
18
18
  s.add_dependency("bresson")
19
+ s.add_dependency("dalli")
19
20
 
20
21
  s.files = `git ls-files`.split("\n")
21
22
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: towsta
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
- - 0
8
- - 4
9
6
  - 1
10
- version: 0.4.1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Mortaro
@@ -15,7 +14,8 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-10-20 00:00:00 Z
17
+ date: 2011-10-28 00:00:00 -02:00
18
+ default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: json
@@ -25,7 +25,6 @@ dependencies:
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- hash: 3
29
28
  segments:
30
29
  - 0
31
30
  version: "0"
@@ -39,12 +38,24 @@ dependencies:
39
38
  requirements:
40
39
  - - ">="
41
40
  - !ruby/object:Gem::Version
42
- hash: 3
43
41
  segments:
44
42
  - 0
45
43
  version: "0"
46
44
  type: :runtime
47
45
  version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: dalli
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ type: :runtime
58
+ version_requirements: *id003
48
59
  description: Simply integrates the towsta api
49
60
  email:
50
61
  - mortaro@towsta.com
@@ -59,11 +70,13 @@ files:
59
70
  - Gemfile
60
71
  - Rakefile
61
72
  - lib/towsta.rb
73
+ - lib/towsta/memory.rb
62
74
  - lib/towsta/synchronizer.rb
63
75
  - lib/towsta/tree.rb
64
76
  - lib/towsta/version.rb
65
77
  - lib/towsta/vertical.rb
66
78
  - towsta.gemspec
79
+ has_rdoc: true
67
80
  homepage: http://rubygems.org/gems/towsta
68
81
  licenses: []
69
82
 
@@ -77,7 +90,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
90
  requirements:
78
91
  - - ">="
79
92
  - !ruby/object:Gem::Version
80
- hash: 3
81
93
  segments:
82
94
  - 0
83
95
  version: "0"
@@ -86,14 +98,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
98
  requirements:
87
99
  - - ">="
88
100
  - !ruby/object:Gem::Version
89
- hash: 3
90
101
  segments:
91
102
  - 0
92
103
  version: "0"
93
104
  requirements: []
94
105
 
95
106
  rubyforge_project: towsta
96
- rubygems_version: 1.7.2
107
+ rubygems_version: 1.3.7
97
108
  signing_key:
98
109
  specification_version: 3
99
110
  summary: Api Integration gem with towsta