Class: Glue::API
- Inherits:
-
FormatHelper
- Object
- FormatHelper
- Glue::API
- Defined in:
- lib/glue.rb
Constant Summary collapse
- POST =
'/api/post'
- USER =
'/api/user'
Instance Attribute Summary collapse
-
#site ⇒ Object
Returns the value of attribute site.
Instance Method Summary collapse
-
#initialize(subdomain, user, pass) ⇒ API
constructor
A new instance of API.
- #post(title, body, *opts) ⇒ Object
- #user_info ⇒ Object
- #valid_site? ⇒ Boolean
Constructor Details
#initialize(subdomain, user, pass) ⇒ API
Returns a new instance of API.
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
#site ⇒ Object
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_info ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/glue.rb', line 32 def user_info response = self.class.post( USER, :query => {}, :basic_auth => @auth ) response['rsp'] ? response : {} end |
#valid_site? ⇒ Boolean
28 29 30 |
# File 'lib/glue.rb', line 28 def valid_site? login_page.match(/<body[^>]*id=["']login["']/) ? true : false end |