bitmarkable 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e890b5dc86f7c126f4a0863628edcfca8010f4c7
4
- data.tar.gz: b272a1d79dfb9eaad955aa4e4e78e831f8164f6e
3
+ metadata.gz: b7554826b5ebf3ec1a0c55ca167e8d2915067af5
4
+ data.tar.gz: c2f68980e91187e5a8831f12b33ac8bfcace9160
5
5
  SHA512:
6
- metadata.gz: 1fa176d0a208d11b544fb3604217d3a96e6ac4a32f29112b05df390ec955b675fbccbd745f258722597ffede5dae42058d5dd8b3499cdb8eb246b27d68b34030
7
- data.tar.gz: 49101feec70242ae29d80c17f8d49f83486edd0a2dec4b8b00cd721e3ce16c461b356d729ce8f6cd39ca15ac2364bbd861cca486f0098841efb5424136a876b5
6
+ metadata.gz: 1d027139bf4c3704e0810d6533c64fa65a91a70aec68143ae540ee6fa64602edf81b69fc5c99cb531d2806f4be31926796822e7614c781ce0c20395446c352a6
7
+ data.tar.gz: 8c405a09f2ebc4a1cf31f33ded440bce72080a5c6fdcf45c30cb58394094666a126b2455ff4b184db7e5928b4043517b25aa923f907691295762533e368aa091
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Bitmarkable
2
2
 
3
- TODO: Write a gem description
3
+ Generate and persist a bitly URL to an ActiveRecord object using Redis.
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,24 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ ```ruby
22
+ Bitmarkable.configure do |c|
23
+ c.login = "username" # bitly username
24
+ c.api_key = "12345" # https://bitly.com/a/your_api_key
25
+ c.base_url = Rails.application.config.base_url # base URL to prepend, if you're using relative paths
26
+ end
27
+ ```
28
+
29
+ Then, include it in your model.
30
+
31
+ ```ruby
32
+ include Bitmarkable::Bitmark
33
+ bitmark :site_url # optional method/attribute containing the URL to shorten, defaults to :url
34
+ ```
35
+
36
+ The short URL can then be fetched using `instance.bitmark`. The value is stored in Redis with the key `class_name:id:bitmark`.
37
+
38
+ If the bitmarkable class responds to `.delay` (e.g. you're using DelayedJob or Sidekiq) then bitmarks will be processed asynchronously.
22
39
 
23
40
  ## Contributing
24
41
 
@@ -9,13 +9,28 @@ module Bitmarkable
9
9
  cattr_accessor :url_field
10
10
  after_save :generate_bitmark
11
11
 
12
- def self.bitmark(url_field = nil)
13
- base_class.url_field = url_field || 'url'
14
- end
12
+ bitmark self.url_field || 'url'
15
13
 
16
14
  def generate_bitmark
17
- self.bitmark = Bitly.shorten(Bitmarkable.configuration.base_url + self.send(url_field.to_sym))
15
+ if self.class.respond_to? :delay
16
+ self.class.delay.save_bitmark(self, "#{Bitmarkable.config.base_url}#{self.send(url_field.to_sym)}")
17
+ else
18
+ self.class.save_bitmark(self, "#{Bitmarkable.config.base_url}#{self.send(url_field.to_sym)}")
19
+ end
20
+ end
21
+ end
22
+
23
+ module ClassMethods
24
+ def bitmark(url_field = nil)
25
+ self.url_field = url_field
26
+ end
27
+
28
+ def save_bitmark(object, url)
29
+ object.bitmark = Bitly.shorten(url)
18
30
  end
19
31
  end
32
+
33
+ extend ClassMethods
34
+
20
35
  end
21
36
  end
@@ -12,6 +12,6 @@ module Bitmarkable
12
12
  end
13
13
 
14
14
  def self.configure
15
- yield(configuration) if block_given?
15
+ yield(config) if block_given?
16
16
  end
17
17
  end
data/lib/bitmarkable.rb CHANGED
@@ -2,10 +2,10 @@ require "active_support"
2
2
  require "active_record"
3
3
  require "httparty"
4
4
  require "redis-objects"
5
- require "bitmarkable/configuration"
5
+ require "bitmarkable/config"
6
6
  require "bitmarkable/bitmark"
7
7
  require "bitmarkable/bitly"
8
8
 
9
9
  module Bitmarkable
10
- VERSION = "0.0.1"
10
+ VERSION = "0.0.2"
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitmarkable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Friedman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-08 00:00:00.000000000 Z
11
+ date: 2013-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -111,7 +111,7 @@ files:
111
111
  - lib/bitmarkable.rb
112
112
  - lib/bitmarkable/bitly.rb
113
113
  - lib/bitmarkable/bitmark.rb
114
- - lib/bitmarkable/configuration.rb
114
+ - lib/bitmarkable/config.rb
115
115
  homepage: ''
116
116
  licenses:
117
117
  - MIT