diff --git a/README.md b/README.md index 1cc595e..ba0228f 100644 --- a/README.md +++ b/README.md @@ -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' @@ -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 diff --git a/lib/plurky/api.rb b/lib/plurky/api.rb new file mode 100644 index 0000000..bfd370f --- /dev/null +++ b/lib/plurky/api.rb @@ -0,0 +1,7 @@ +require 'plurky/api/timeline' + +module Plurky + module API + include Plurky::API::Timeline + end +end diff --git a/lib/plurky/api/timeline.rb b/lib/plurky/api/timeline.rb new file mode 100644 index 0000000..ea19711 --- /dev/null +++ b/lib/plurky/api/timeline.rb @@ -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 diff --git a/lib/plurky/client.rb b/lib/plurky/client.rb index 0cc7230..4be7d76 100644 --- a/lib/plurky/client.rb +++ b/lib/plurky/client.rb @@ -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 diff --git a/lib/plurky/status.rb b/lib/plurky/status.rb new file mode 100644 index 0000000..e69de29 diff --git a/spec/fixtures/status.json b/spec/fixtures/status.json new file mode 100644 index 0000000..640e4bb --- /dev/null +++ b/spec/fixtures/status.json @@ -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": "Finally, a command line shell for the 90s<\/a> ", "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}} \ No newline at end of file diff --git a/spec/plurky/api/timeline_spec.rb b/spec/plurky/api/timeline_spec.rb new file mode 100644 index 0000000..2468e45 --- /dev/null +++ b/spec/plurky/api/timeline_spec.rb @@ -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 diff --git a/spec/plurky_spec.rb b/spec/plurky_spec.rb index 427fbc5..8d413be 100644 --- a/spec/plurky_spec.rb +++ b/spec/plurky_spec.rb @@ -32,4 +32,7 @@ end end + describe ".configure" do + end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ead730d..68060a2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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