Skip to content

Commit

Permalink
Merge pull request #6 from Krystosterone/whitelist
Browse files Browse the repository at this point in the history
Implementation of whitelist api
  • Loading branch information
royjs committed Oct 20, 2014
2 parents 78b3360 + 1fb505c commit 07a475c
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/mollom_rest_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module MollomRestApi
require 'mollom_rest_api/v1/feedback'
require 'mollom_rest_api/v1/site'
require 'mollom_rest_api/v1/blacklist'
require 'mollom_rest_api/v1/whitelist'

class << self
attr_accessor :url, :public_key, :private_key, :oauth_options
Expand Down
31 changes: 31 additions & 0 deletions lib/mollom_rest_api/v1/whitelist.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class MollomRestApi::V1::Whitelist < MollomRestApi::Interface

def self.create(public_key, value, context, request_parameters = {})
post(request_parameters.reverse_merge(value: value, context: context), [public_key])
end

def self.update(public_key, whitelist_entry_id, request_parameters = {})
post(request_parameters, [public_key, whitelist_entry_id])
end

def self.delete(public_key, whitelist_entry_id)
post({}, [public_key, whitelist_entry_id])
end

def self.list(public_key, request_parameters = {})
get(request_parameters, [public_key])
end

def self.read(public_key, whitelist_entry_id)
get({}, [public_key, whitelist_entry_id])
end

class << self
protected

def results_key
'entry'
end
end

end
43 changes: 43 additions & 0 deletions spec/fixtures/cassette_library/whitelist/create.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions spec/fixtures/cassette_library/whitelist/delete.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions spec/fixtures/cassette_library/whitelist/list.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions spec/fixtures/cassette_library/whitelist/read.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions spec/fixtures/cassette_library/whitelist/update.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spec/mollom_rest_api/v1/blacklist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
end

describe :read do
context "when providing a public key and blacklist entry id", vcr: {cassette_name: "blacklist/read", record: :new_episodes} do
context "when providing a public key and blacklist entry id", vcr: {cassette_name: "blacklist/read"} do
let(:response) {{"context"=>"allFields", "created"=>"1410452568617", "id"=>"68172853-2a81-4899-b09a-ff1f1bad88aa", "match"=>"contains", "note"=>"", "reason"=>"unwanted", "status"=>"1", "value"=>"text"}}

it "should return a json response containing the blacklist entry" do
Expand Down
64 changes: 64 additions & 0 deletions spec/mollom_rest_api/v1/whitelist_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require "spec_helper"

describe MollomRestApi::V1::Whitelist do
describe :create do
context "when providing a valid url and email", vcr: {cassette_name: "whitelist/create"} do
let(:request_parameters) { {note: 'patate'} }
let(:response) {{"context"=>"authorIp", "created"=>"1412787909465", "id"=>"76747", "lastMatch"=>"0", "matchCount"=>"0", "status"=>"1", "value"=>"123.123.80.22"}}

it "should return a json response containing the whitelist entry" do
expect(MollomRestApi::V1::Whitelist.create('1lgj17lzuezlu1bn9ry4k3qz4k8nr42n', '123.123.80.22', 'authorIp', request_parameters)).to eq(response)
end
end

include_examples "api error handling", class_under_test: MollomRestApi::V1::Whitelist, method_under_test: :create, method_args: %w(public_key value context)
end

describe :update do
context "when providing a public key and a value for an author name", vcr: {cassette_name: "whitelist/update"} do
let(:request_parameters) { {value: 'patate', context: 'authorName'} }
let(:response) {{"context"=>"authorName", "created"=>"1412787909465", "id"=>"76747", "lastMatch"=>"0", "matchCount"=>"0", "status"=>"0", "value"=>"patate"}}

it "should return a json response containing the updated whitelist entry" do
expect(MollomRestApi::V1::Whitelist.update('1lgj17lzuezlu1bn9ry4k3qz4k8nr42n', '76747', request_parameters)).to eq(response)
end
end

include_examples "api error handling", class_under_test: MollomRestApi::V1::Whitelist, method_under_test: :update, method_args: %w(public_key whitelist_entry_id)
end

describe :delete do
context "when providing a public key and whitelist entry id", vcr: {cassette_name: "whitelist/delete"} do
it "should return a json response containing the deleted whitelist entry" do
expect{MollomRestApi::V1::Whitelist.delete('1lgj17lzuezlu1bn9ry4k3qz4k8nr42n', '79552')}.not_to raise_error
end
end

include_examples "api error handling", class_under_test: MollomRestApi::V1::Whitelist, method_under_test: :delete, method_args: %w(public_key whitelist_entry_id)
end

describe :list do
context "when providing a public key", vcr: {cassette_name: "whitelist/list"} do
let(:request_parameters) { {count: 5} }
let(:response) {{"entry"=>{"context"=>"authorName", "created"=>"1412787909465", "id"=>"76747", "lastMatch"=>"0", "matchCount"=>"0", "status"=>"0", "value"=>"patate"}}}

it "should return a json response containing the list of whitelist entries" do
expect(MollomRestApi::V1::Whitelist.list('1lgj17lzuezlu1bn9ry4k3qz4k8nr42n', request_parameters)).to eq(response)
end
end

include_examples "api error handling", class_under_test: MollomRestApi::V1::Whitelist, method_under_test: :list, method_args: %w(a_public_key)
end

describe :read do
context "when providing a public key and whitelist entry id", vcr: {cassette_name: "whitelist/read"} do
let(:response) {{"context"=>"authorName", "created"=>"1413826721455", "id"=>"79557", "lastMatch"=>"0", "matchCount"=>"0", "status"=>"1", "value"=>"patate"}}

it "should return a json response containing the whitelist entry" do
expect(MollomRestApi::V1::Whitelist.read('1lgj17lzuezlu1bn9ry4k3qz4k8nr42n', '79557')).to eq(response)
end
end

include_examples "api error handling", class_under_test: MollomRestApi::V1::Whitelist, method_under_test: :read, method_args: %w(public_key whitelist_entry_id)
end
end

0 comments on commit 07a475c

Please sign in to comment.