bitmarkable 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/README.md +19 -2
- data/lib/bitmarkable/bitmark.rb +19 -4
- data/lib/bitmarkable/{configuration.rb → config.rb} +1 -1
- data/lib/bitmarkable.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7554826b5ebf3ec1a0c55ca167e8d2915067af5
|
4
|
+
data.tar.gz: c2f68980e91187e5a8831f12b33ac8bfcace9160
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d027139bf4c3704e0810d6533c64fa65a91a70aec68143ae540ee6fa64602edf81b69fc5c99cb531d2806f4be31926796822e7614c781ce0c20395446c352a6
|
7
|
+
data.tar.gz: 8c405a09f2ebc4a1cf31f33ded440bce72080a5c6fdcf45c30cb58394094666a126b2455ff4b184db7e5928b4043517b25aa923f907691295762533e368aa091
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Bitmarkable
|
2
2
|
|
3
|
-
|
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
|
-
|
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
|
|
data/lib/bitmarkable/bitmark.rb
CHANGED
@@ -9,13 +9,28 @@ module Bitmarkable
|
|
9
9
|
cattr_accessor :url_field
|
10
10
|
after_save :generate_bitmark
|
11
11
|
|
12
|
-
|
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.
|
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
|
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/
|
5
|
+
require "bitmarkable/config"
|
6
6
|
require "bitmarkable/bitmark"
|
7
7
|
require "bitmarkable/bitly"
|
8
8
|
|
9
9
|
module Bitmarkable
|
10
|
-
VERSION = "0.0.
|
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.
|
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-
|
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/
|
114
|
+
- lib/bitmarkable/config.rb
|
115
115
|
homepage: ''
|
116
116
|
licenses:
|
117
117
|
- MIT
|