Class: Postly::Connection

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/postly/connection.rb

Direct Known Subclasses

Comment, Post, Site

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Connection

Returns a new instance of Connection.



8
9
10
# File 'lib/postly/connection.rb', line 8

def initialize attrs={}
  attrs.each_pair {|k,v| send("#{k}=".to_sym, v) if respond_to? "#{k}=".to_sym }
end

Class Method Details

.array_or_hash(response) ⇒ Object



28
29
30
# File 'lib/postly/connection.rb', line 28

def self.array_or_hash response
  response["rsp"][self.class_name.downcase]
end

.class_nameObject

Split off the Namespace



33
34
35
# File 'lib/postly/connection.rb', line 33

def self.class_name
  @class_name ||= self.to_s.split("::").last
end

.conform(response) ⇒ Object

quack! quack!



18
19
20
21
22
23
24
25
26
# File 'lib/postly/connection.rb', line 18

def self.conform response
  result = array_or_hash response
   case result
   when Hash
     self.new result
   when Array
     result.collect { |item| self.new item }
   end
end

.defaultsObject



12
13
14
15
# File 'lib/postly/connection.rb', line 12

def self.defaults
  { :basic_auth => {:username => Postly.config["username"], 
    :password => Postly.config["password"]} }
end

.many(collection_name) ⇒ Object



38
39
40
41
42
# File 'lib/postly/connection.rb', line 38

def self.many collection_name
  define_method collection_name do
    ManyProxy.new self, singularized_class_name(collection_name)
  end
end

Instance Method Details

#singularized_class_name(collection_name) ⇒ Object



44
45
46
47
# File 'lib/postly/connection.rb', line 44

def singularized_class_name collection_name
  "Postly::#{collection_name.to_s.singularize.camelize}".constantize
  # collection_name.to_s.singularize.camelize.constantize
end