Module: Forrst

Defined in:
lib/forrst.rb,
lib/forrst/post.rb,
lib/forrst/user.rb,
lib/forrst/comment.rb,
lib/forrst/version.rb

Overview

The Forrst gem is an API library for the Forrst API that focuses on stability, ease of use and minimal dependencies.

Author:

  • Yorick Peterse

Since:

  • 0.1a

Defined Under Namespace

Classes: Comment, Post, User

Constant Summary collapse

URL =

The URL to the API endpoint.

Author:

  • Yorick Peterse

Since:

  • 0.1a

'http://forrst.com/api/v2/'
StatisticsURL =

URL relative to Forrst::URL that contains all the API statistics.

Author:

  • Yorick Peterse

Since:

  • 0.1a

'/stats'
DateFormat =

A string containing the date format used for all dates returned by the API.

Author:

  • Yorick Peterse

Since:

  • 0.1a

'%Y-%m-%d %H:%M:%S'
Version =

Since:

  • 0.1a

'0.1.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.access_tokenObject

The access token returned once a client has been authorized.

Since:

  • 0.1a



44
45
46
# File 'lib/forrst.rb', line 44

def access_token
  @access_token
end

.idObject

The ID of the application as provided by Forrst.

Since:

  • 0.1a



47
48
49
# File 'lib/forrst.rb', line 47

def id
  @id
end

.oauthObject

Instance of OAuth2::Client.

Since:

  • 0.1a



53
54
55
# File 'lib/forrst.rb', line 53

def oauth
  @oauth
end

.secretObject

The secret of the application as provided by Forrst.

Since:

  • 0.1a



50
51
52
# File 'lib/forrst.rb', line 50

def secret
  @secret
end

Class Method Details

.configure { ... } ⇒ Object

Sets various configuration options in the module so that they can be used by other parts of this gem.

Examples:

Forrst.configure do |client|
  client.access_token = '1234abc'
end

Yields:

  • self

Author:

  • Yorick Peterse

Since:

  • 0.1a



68
69
70
71
72
# File 'lib/forrst.rb', line 68

def configure
  yield self

  @oauth = OAuth2::Client.new(@id, @secret, :site => URL)
end

.statisticsHash

Gets a set of statistics from the API server.

Examples:

stats = Forrst.statistics
stats[:limit] # => 150

Returns:

Author:

  • Yorick Peterse

Since:

  • 0.1a



85
86
87
88
89
90
91
92
93
94
# File 'lib/forrst.rb', line 85

def statistics
  response = @oauth.request(:get, StatisticsURL)
  response = JSON.load(response)
  hash     = {
    :limit => response['resp']['rate_limit'].to_i,
    :calls => response['resp']['calls_made'].to_i
  }

  return hash
end