Class: Glue::API

Inherits:
FormatHelper show all
Defined in:
lib/glue.rb

Constant Summary collapse

POST =
'/api/post'
USER =
'/api/user'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subdomain, user, pass) ⇒ API

Returns a new instance of API.

Raises:



20
21
22
23
24
25
26
# File 'lib/glue.rb', line 20

def initialize subdomain, user, pass
  raise  AuthError, 'Username, Password or Account subdomain is blank.' \
    if subdomain.empty? || user.empty? || pass.empty?
  @auth   = { :username => user, :password => pass }
  @site   = "#{subdomain}.#{DOMAIN}"
  self.class.base_uri @site
end

Instance Attribute Details

#siteObject

Returns the value of attribute site.



18
19
20
# File 'lib/glue.rb', line 18

def site
  @site
end

Instance Method Details

#post(title, body, *opts) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/glue.rb', line 42

def post title, body, *opts
  response = self.class.post(
    POST,
    :query      =>  {
    :title      =>  title,
    :body       =>  body,
    :draft      =>  opts.include?( :draft  )  ,
    :author     =>  opts.include?( :author )  },
    :basic_auth =>  @auth
  )
  response['rsp'] ? response : {}
  
end

#user_infoObject



32
33
34
35
36
37
38
39
40
# File 'lib/glue.rb', line 32

def 
  response = self.class.post(
    USER,
    :query      => {},
    :basic_auth => @auth
  )
  response['rsp'] ? response : {}

end

#valid_site?Boolean

Returns:

  • (Boolean)


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

def valid_site?
  .match(/<body[^>]*id=["']login["']/) ? true : false
end