Class: SimpleTumblr

Inherits:
Object
  • Object
show all
Includes:
Enumerable, HTTParty
Defined in:
lib/simple_tumblr.rb,
lib/simple_tumblr/version.rb

Defined Under Namespace

Classes: Post

Constant Summary collapse

VERSION =
'0.1.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SimpleTumblr

Returns a new instance of SimpleTumblr.



10
11
12
# File 'lib/simple_tumblr.rb', line 10

def initialize(options = {})
  self.options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/simple_tumblr.rb', line 7

def options
  @options
end

Class Method Details

.method_missing(method, *args, &block) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/simple_tumblr.rb', line 43

def method_missing(method, *args, &block)
  instance = new
  
  if instance.respond_to?(method)
    instance.options = args.extract_options!
    
    if instance.method(method).arity == 1
      instance.send(method, args)
    else
      instance.send(method)
    end
  else
    super
  end
end

Instance Method Details

#each(&block) ⇒ Object



35
36
37
38
39
40
# File 'lib/simple_tumblr.rb', line 35

def each(&block)
  response = self.class.get("/v2/blog/#{self.options.delete(:hostname)}/posts", query: @options)
  raise response['meta']['msg'] unless response.success?

  response['response']['posts'].map { |data| Post.new(data) }.each(&block)
end

#posts(options = {}) ⇒ Object



14
15
16
17
# File 'lib/simple_tumblr.rb', line 14

def posts(options = {})
  self.options = self.options.merge(options)
  self
end