Module: Corkboard
- Defined in:
- lib/corkboard.rb,
lib/corkboard/client.rb,
lib/corkboard/engine.rb,
lib/corkboard/version.rb,
lib/corkboard/provider.rb,
lib/corkboard/service/config.rb,
lib/corkboard/publishers/mock.rb,
lib/corkboard/clients/instagram.rb,
lib/corkboard/publishers/pusher.rb,
lib/corkboard/providers/instagram.rb,
lib/generators/corkboard/install_generator.rb
Defined Under Namespace
Modules: Client, Clients, Generators, Provider, Providers, Publishers, Service Classes: ActionForbidden, Engine
Constant Summary collapse
- VERSION =
"0.1.3"
- @@redis =
nil
- @@authentication =
Authentication defaults.
{ :admin => :disallow!, :board => nil }
- @@presentation =
Presentation/view defaults.
{ :title => 'Corkboard', :description => 'Corkboard', :framework => :bootstrap, :weights => { :s => 10, :m => 3, :l => 1 } }
- @@interests =
Interests defaults.
{ :scope => [], :filters => [], }
- @@publisher_configs =
ActiveSupport::OrderedHash.new
- @@service_configs =
ActiveSupport::OrderedHash.new
Class Method Summary collapse
-
.authentication(config = nil) ⇒ Object
Authentication configuration.
- .clear_all! ⇒ Object
-
.client(strategy, options = {}) ⇒ Object
Publishing methods (will likely move elsewhere) ---------------------------------------------------------------------------.
-
.interests(config = nil) ⇒ Object
Interests configuration.
-
.presentation(config = nil) ⇒ Object
Presentation/view configuration.
- .provider_for(key) ⇒ Object
-
.publish!(data) ⇒ Object
TODO: make non-specific to instagram.
-
.publisher(provider, credentials = nil) ⇒ Object
Enable and configure a publisher.
- .publisher_for(key) ⇒ Object
-
.publishers ⇒ Object
Providers for enabled publishers.
-
.service(provider, *args) ⇒ Object
Enable and configure a service.
-
.services ⇒ Object
Providers for enabled services.
-
.setup {|_self| ... } ⇒ Object
The standard mechanism for configuring Corkboard.
Class Method Details
.authentication(config = nil) ⇒ Object
Authentication configuration.
53 54 55 56 57 58 59 |
# File 'lib/corkboard.rb', line 53 def self.authentication(config = nil) if config @@authentication.merge!(config) end @@authentication end |
.clear_all! ⇒ Object
142 143 144 145 |
# File 'lib/corkboard.rb', line 142 def self.clear_all! keys = Corkboard.redis.keys("corkboard:*") Corkboard.redis.del(keys) if keys.present? end |
.client(strategy, options = {}) ⇒ Object
Publishing methods (will likely move elsewhere)
138 139 140 |
# File 'lib/corkboard.rb', line 138 def self.client(strategy, = {}) provider_for(strategy).client() end |
.interests(config = nil) ⇒ Object
Interests configuration.
85 86 87 88 89 90 91 |
# File 'lib/corkboard.rb', line 85 def self.interests(config = nil) if config @@interests.merge!(config) end @@interests end |
.presentation(config = nil) ⇒ Object
Presentation/view configuration.
70 71 72 73 74 75 76 |
# File 'lib/corkboard.rb', line 70 def self.presentation(config = nil) if config @@presentation.merge!(config) end @@presentation end |
.provider_for(key) ⇒ Object
147 148 149 |
# File 'lib/corkboard.rb', line 147 def self.provider_for(key) Corkboard::Providers.const_get(camelcase(key)) end |
.publish!(data) ⇒ Object
TODO: make non-specific to instagram.
TODO: post data
as a collection (fewer http requests sent)
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/corkboard.rb', line 157 def self.publish!(data) received = Time.now.utc.to_i data.reverse.each do |item| eid = item.id key = "corkboard:posts:instagram:#{eid}" entry = Hashie::Mash.new({ :eid => eid, # String :caption => item., # Mash [:text] :images => item.images, # Mash [:low_resolution, standard_resolution, :thumbnail] :link => item.link, # String :location => item.location, # Mash :tags => item., # Array :user => item.user # Mash [:id, :username] }) if Corkboard.redis.setnx(key, "#{received}|#{entry.to_json}") position = Corkboard.redis.incr("corkboard:counters:post") reference = "corkboard:posts:#{position}" Corkboard.redis.set(reference, key) Corkboard.redis.lpush("corkboard:posts", reference) Corkboard.redis.ltrim("corkboard:posts", 0, 1000) publishers.each do |name| publisher_configs[name].publish!(entry) end end end end |
.publisher(provider, credentials = nil) ⇒ Object
Enable and configure a publisher.
config.publisher(:pusher, {
:client_app => 'EXAMPLE',
:client_key => 'EXAMPLE',
:client_secret => 'EXAMPLE'
})
101 102 103 |
# File 'lib/corkboard.rb', line 101 def self.publisher(provider, credentials = nil) @@publisher_configs[provider] = publisher_for(provider).new(credentials) end |
.publisher_for(key) ⇒ Object
151 152 153 |
# File 'lib/corkboard.rb', line 151 def self.publisher_for(key) Corkboard::Publishers.const_get(camelcase(key)) end |
.publishers ⇒ Object
Providers for enabled publishers.
106 107 108 |
# File 'lib/corkboard.rb', line 106 def self.publishers publisher_configs.keys end |
.service(provider, *args) ⇒ Object
Enable and configure a service.
config.service(:instagram,
:client_key => 'EXAMPLE',
:client_secret => 'EXAMPLE'
})
121 122 123 124 |
# File 'lib/corkboard.rb', line 121 def self.service(provider, *args) config = Corkboard::Service::Config.new(provider, args) @@service_configs[provider] = config end |
.services ⇒ Object
Providers for enabled services.
131 132 133 |
# File 'lib/corkboard.rb', line 131 def self.services service_configs.keys end |
.setup {|_self| ... } ⇒ Object
The standard mechanism for configuring Corkboard. Run the following to generate a fresh initializer with configuration defaults and samples:
rails generate corkboard:install
35 36 37 |
# File 'lib/corkboard.rb', line 35 def self.setup yield self end |