Module: Tumblargh::API
- Defined in:
- lib/tumblargh/api.rb
Constant Summary collapse
- API_ROOT =
'http://api.tumblr.com/v2/blog/'
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
Class Method Summary collapse
- .blog(domain) ⇒ Object
- .disable! ⇒ Object
- .enable! ⇒ Object
- .enabled? ⇒ Boolean
- .fetch(path, query = {}) ⇒ Object
- .notes(domain, query) ⇒ Object
- .posts(domain, query = {}) ⇒ Object
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
18 19 20 |
# File 'lib/tumblargh/api.rb', line 18 def api_key @api_key end |
Class Method Details
.blog(domain) ⇒ Object
30 31 32 |
# File 'lib/tumblargh/api.rb', line 30 def blog(domain) fetch("#{domain}/info")['blog'] end |
.disable! ⇒ Object
48 49 50 |
# File 'lib/tumblargh/api.rb', line 48 def disable! @enabled = false end |
.enable! ⇒ Object
44 45 46 |
# File 'lib/tumblargh/api.rb', line 44 def enable! @enabled = true end |
.enabled? ⇒ Boolean
52 53 54 |
# File 'lib/tumblargh/api.rb', line 52 def enabled? @enabled end |
.fetch(path, query = {}) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/tumblargh/api.rb', line 21 def fetch(path, query={}) raise "API is disabled" unless enabled? query = query.merge(:api_key => api_key).to_query url = "#{API_ROOT}#{path}?#{query}" resp = APICache.get(url) { open(url).read } ActiveSupport::JSON.decode(resp)['response'] end |
.notes(domain, query) ⇒ Object
38 39 40 41 |
# File 'lib/tumblargh/api.rb', line 38 def notes(domain, query) query.merge!(:notes_info => 'true') fetch("#{domain}/posts", query)['posts'][0]['notes'] end |
.posts(domain, query = {}) ⇒ Object
34 35 36 |
# File 'lib/tumblargh/api.rb', line 34 def posts(domain, query={}) fetch("#{domain}/posts")['posts'] end |