Skip to content

Commit

Permalink
Add the status API of getting a plurk
Browse files Browse the repository at this point in the history
  • Loading branch information
Domon committed Jun 9, 2013
1 parent b497767 commit 99e817c
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 3 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Or install it yourself as:
* This gem: http://rdoc.info/gems/plurky
* Plurk API 2.0: http://www.plurk.com/API

## Usage
## Examples

```ruby
require 'plurky'
Expand Down Expand Up @@ -70,11 +70,21 @@ After configuration, requests can be made like so:
Plurky.get '/APP/Timeline/getPlurks'
```

## Implemented APIs

* status

## The access token

Plurky will not support obtaining access token.
You can get it from the [test console][].

[test console]: http://www.plurk.com/OAuth/test

## TODO

* Complete the tests.
* Improve test coverage.
* Add APIs.
* Add support of obtaining access token.

## Credits

Expand Down
7 changes: 7 additions & 0 deletions lib/plurky/api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'plurky/api/timeline'

module Plurky
module API
include Plurky::API::Timeline
end
end
27 changes: 27 additions & 0 deletions lib/plurky/api/timeline.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Plurky
module API
module Timeline
# Returns a status
#
# @see http://www.plurk.com/API#/APP/Timeline/getPlurk
# @return [Hashie::Mash] The requested status.
# @param id [Integer] A status ID.
# @example Return the status with the ID 1001647781
# Plurky.status(1001647781)
def status(id)
object_from_response(:get, "/APP/Timeline/getPlurk", { :plurk_id => id }).plurk
end

private

# @param method [Symbol]
# @param url [String]
# @param params [Hash]
# @return [Hashie::Mash]
def object_from_response(method, url, params = {})
response = send(method, url, params)
response[:body]
end
end
end
end
3 changes: 3 additions & 0 deletions lib/plurky/client.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
require 'faraday'
require 'simple_oauth'
require 'uri'
require 'plurky/api'
require 'plurky/configurable'

module Plurky
# Wrapper for the Plurk API 2.0
class Client
include Plurky::API
include Plurky::Configurable

# Initializes a new Client object
Expand Down
Empty file added lib/plurky/status.rb
Empty file.
1 change: 1 addition & 0 deletions spec/fixtures/status.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"plurk_users": {"1": {"verified_account": false, "default_lang": "en", "display_name": "amix", "dateformat": 0, "nick_name": "amix", "has_profile_image": 1, "location": "", "bday_privacy": 2, "date_of_birth": "Mon, 13 May 1985 00:01:00 GMT", "karma": 69.6, "full_name": "Amir Salihefendic", "gender": 1, "name_color": "0A9C17", "timezone": "Europe\/Amsterdam", "id": 1, "avatar": 34}}, "user": {"verified_account": false, "default_lang": "en", "display_name": "amix", "dateformat": 0, "nick_name": "amix", "has_profile_image": 1, "location": "", "bday_privacy": 2, "date_of_birth": "Mon, 13 May 1985 00:01:00 GMT", "karma": 69.6, "full_name": "Amir Salihefendic", "gender": 1, "name_color": "0A9C17", "timezone": "Europe\/Amsterdam", "id": 1, "avatar": 34}, "plurk": {"replurkers_count": 4, "replurkable": true, "favorite_count": 6, "is_unread": 0, "favorers": [24228, 89434, 3184175, 3633219, 5386772, 6693159], "user_id": 1, "plurk_type": 0, "replurked": false, "content": "<a href=\"http:\/\/ridiculousfish.com\/shell\/index.html\" class=\"ex_link\" rel=\"nofollow\">Finally, a command line shell for the 90s<\/a> <img class=\"emoticon_my\" src=\"http:\/\/emos.plurk.com\/b6ebb0a088fa352ee03ed6f760fb319d_w16_h16.png\" width=\"16\" height=\"16\" \/>", "replurker_id": null, "owner_id": 1, "responses_seen": 0, "qualifier": "likes", "plurk_id": 1001647781, "response_count": 8, "limited_to": null, "no_comments": 0, "posted": "Wed, 06 Jun 2012 12:37:42 GMT", "lang": "en", "content_raw": "http:\/\/ridiculousfish.com\/shell\/index.html (Finally, a command line shell for the 90s) http:\/\/emos.plurk.com\/b6ebb0a088fa352ee03ed6f760fb319d_w16_h16.png", "replurkers": [23118, 3184175, 4853404, 6649986], "favorite": true}}
24 changes: 24 additions & 0 deletions spec/plurky/api/timeline_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'spec_helper'

describe Plurky::API::Timeline do
subject(:client) { Plurky::Client.new }

describe "#status" do
before do
stub_get("/APP/Timeline/getPlurk", :plurk_id => 1001647781).
to_return(json_response("status.json"))
end

it "requests the correct resource" do
client.status(1001647781)
expect(a_get("/APP/Timeline/getPlurk", :plurk_id => 1001647781)).to have_been_made
end

it "returns a correct Hashie::Mash" do
status = client.status(1001647781)
expect(status).to be_a Hashie::Mash
expect(status.content_raw).to eq "http://ridiculousfish.com/shell/index.html (Finally, a command line shell for the 90s) http://emos.plurk.com/b6ebb0a088fa352ee03ed6f760fb319d_w16_h16.png"
end
end

end
3 changes: 3 additions & 0 deletions spec/plurky_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@
end
end

describe ".configure" do
end

end
33 changes: 33 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,36 @@
c.syntax = :expect
end
end

def plurk_url(path)
URI.join(Plurky::Default::ENDPOINT, path).to_s
end

def a_get(path, query = {})
a_request(:get, plurk_url(path)).with(:query => query)
end

def stub_get(path, query = {})
stub_request(:get, plurk_url(path)).with(:query => query)
end

def fixtures_path
File.expand_path("../fixtures", __FILE__)
end

def fixture_path(file)
File.join(fixtures_path, file)
end

def fixture(file)
File.new(fixture_path(file))
end

def json_response(file)
{
:body => fixture(file),
:headers => {
:content_type => "application/json; charset=utf-8"
}
}
end

0 comments on commit 99e817c

Please sign in to comment.