rsimpy 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +7 -0
- data/LICENSE +20 -0
- data/README.rdoc +21 -0
- data/Rakefile +96 -0
- data/VERSION.yml +4 -0
- data/bin/simp +68 -0
- data/features/links/adding_a_link.feature +47 -0
- data/features/links/querying_links.feature +46 -0
- data/features/links/steps/link_steps.rb +39 -0
- data/features/notes/query_note.feature +27 -0
- data/features/notes/remove_note.feature +11 -0
- data/features/notes/save_note.feature +36 -0
- data/features/notes/steps/note_steps.rb +46 -0
- data/features/support/env.rb +22 -0
- data/features/tags/merge_tags.feature +13 -0
- data/features/tags/querying_tags.feature +19 -0
- data/features/tags/remove_tag.feature +11 -0
- data/features/tags/rename_tag.feature +12 -0
- data/features/tags/split_tag.feature +13 -0
- data/features/tags/steps/tag_steps.rb +49 -0
- data/lib/base_service.rb +28 -0
- data/lib/client.rb +45 -0
- data/lib/configuration.rb +21 -0
- data/lib/errors/connection_error.rb +6 -0
- data/lib/errors/required_field_missing_error.rb +9 -0
- data/lib/errors/user_not_provided_error.rb +4 -0
- data/lib/links.rb +62 -0
- data/lib/parameters.rb +120 -0
- data/lib/posting_service.rb +27 -0
- data/lib/profile_storage_service.rb +47 -0
- data/lib/querying_service.rb +31 -0
- data/lib/rsimpy.rb +62 -0
- data/lib/user.rb +31 -0
- data/rsimpy.gemspec +128 -0
- data/test/client_test.rb +40 -0
- data/test/configuration_test.rb +27 -0
- data/test/deleting_service_test.rb +51 -0
- data/test/fixtures/test +5 -0
- data/test/fixtures/user_pass +5 -0
- data/test/links_test.rb +47 -0
- data/test/parameters_test.rb +61 -0
- data/test/posting_service_test.rb +45 -0
- data/test/profile_storage_service_test.rb +34 -0
- data/test/querying_service_test.rb +31 -0
- data/test/r_simpy_test.rb +74 -0
- data/test/required_field_missing_error_test.rb +11 -0
- data/test/responsive.rb +154 -0
- data/test/storage_builder.rb +16 -0
- data/test/storage_service_mock.rb +16 -0
- data/test/test_helper.rb +18 -0
- data/test/user_not_provided_error_test.rb +7 -0
- data/test/user_test.rb +34 -0
- metadata +182 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'base_service'
|
2
|
+
|
3
|
+
module RSimpy
|
4
|
+
MERGE_TAGS = 'MergeTags'
|
5
|
+
SPLIT_TAG = 'SplitTag'
|
6
|
+
RENAME_TAG = "RenameTag"
|
7
|
+
REMOVE_TAG = 'RemoveTag'
|
8
|
+
DELETE_LINK = 'DeleteLink'
|
9
|
+
SAVE_LINK = 'SaveLink'
|
10
|
+
DELETE_NOTE = 'DeleteNote'
|
11
|
+
SAVE_NOTE = 'SaveNote'
|
12
|
+
|
13
|
+
class PostingService < RSimpy::BaseService
|
14
|
+
def initialize command, client
|
15
|
+
@command = command
|
16
|
+
@client = client
|
17
|
+
end
|
18
|
+
|
19
|
+
def execute params
|
20
|
+
execute_using :post, params
|
21
|
+
end
|
22
|
+
|
23
|
+
def build_link params
|
24
|
+
"/#{@command}.do?" << params.to_querystring
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module RSimpy
|
2
|
+
class ProfileStorageService
|
3
|
+
def initialize location=nil
|
4
|
+
@location = location || default_location
|
5
|
+
end
|
6
|
+
|
7
|
+
def default_location
|
8
|
+
File.expand_path(File.join(['~','.rsimpy']))
|
9
|
+
end
|
10
|
+
|
11
|
+
def stored?
|
12
|
+
File.exists? @location
|
13
|
+
end
|
14
|
+
|
15
|
+
def save user
|
16
|
+
require 'khayyam'
|
17
|
+
|
18
|
+
topic = Khayyam::Topic.new "rsimpy"
|
19
|
+
topic.regarding "user" do |items|
|
20
|
+
login, pass = user.credentials
|
21
|
+
items["login"] = login
|
22
|
+
items["pass"] = pass
|
23
|
+
end
|
24
|
+
|
25
|
+
output = topic.export
|
26
|
+
|
27
|
+
file = File.open(@location, 'w+')
|
28
|
+
file.write(output)
|
29
|
+
file.close
|
30
|
+
end
|
31
|
+
|
32
|
+
def get
|
33
|
+
file = File.read(@location)
|
34
|
+
data = {}
|
35
|
+
require 'khayyam'
|
36
|
+
login, pass = nil
|
37
|
+
|
38
|
+
topic = Khayyam::Topic.import file
|
39
|
+
topic.regarding "user" do |items|
|
40
|
+
login = items["login"]
|
41
|
+
pass = items["pass"]
|
42
|
+
end
|
43
|
+
|
44
|
+
return RSimpy::User.new(login, pass)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'base_service'
|
2
|
+
|
3
|
+
module RSimpy
|
4
|
+
GET_TAGS = "GetTags"
|
5
|
+
GET_LINKS = "GetLinks"
|
6
|
+
GET_NOTES = "GetNotes"
|
7
|
+
|
8
|
+
class QueryingService < RSimpy::BaseService
|
9
|
+
|
10
|
+
def initialize command, client
|
11
|
+
@client = client
|
12
|
+
@command = command
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute params
|
16
|
+
params = RSimpy::Parameters.new unless params
|
17
|
+
|
18
|
+
reset
|
19
|
+
response = @client.get build_link params
|
20
|
+
|
21
|
+
@success = (response.code == 200)
|
22
|
+
|
23
|
+
response
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_link params
|
27
|
+
params.add(:src, 'rsimpy')
|
28
|
+
"/#{@command}.do?" << params.to_querystring
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/rsimpy.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
require 'client'
|
3
|
+
require 'user'
|
4
|
+
require 'parameters'
|
5
|
+
require 'configuration'
|
6
|
+
require 'profile_storage_service'
|
7
|
+
require 'posting_service'
|
8
|
+
require 'querying_service'
|
9
|
+
require 'links'
|
10
|
+
require 'errors/user_not_provided_error'
|
11
|
+
|
12
|
+
module RSimpy
|
13
|
+
def get_links param_hash={}
|
14
|
+
user = build_user param_hash
|
15
|
+
params = build_params param_hash
|
16
|
+
|
17
|
+
client = RSimpy::Client.new(user)
|
18
|
+
service = RSimpy::QueryingService.new RSimpy::GET_LINKS, client
|
19
|
+
|
20
|
+
result = service.execute params
|
21
|
+
result[:success] = service.success
|
22
|
+
result
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete_link param_hash={}
|
26
|
+
user = build_user param_hash
|
27
|
+
|
28
|
+
client = RSimpy::Client.new(user)
|
29
|
+
service = RSimpy::PostingService.new RSimpy::DELETE_LINK, client
|
30
|
+
|
31
|
+
service.execute param_hash[:params]
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def build_user param_hash
|
36
|
+
login = param_hash[:login] if param_hash.has_key? :login
|
37
|
+
pass = param_hash[:pass] if param_hash.has_key? :pass
|
38
|
+
|
39
|
+
if login && pass
|
40
|
+
return RSimpy::User.new login, pass
|
41
|
+
end
|
42
|
+
|
43
|
+
build_user_from_configuration param_hash
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_params param_hash
|
47
|
+
param_hash[:params] || RSimpy::Parameters.new
|
48
|
+
end
|
49
|
+
|
50
|
+
def build_user_from_configuration param_hash
|
51
|
+
storage_service = RSimpy::ProfileStorageService.new(param_hash[:config_file])
|
52
|
+
config = RSimpy::Configuration.new storage_service
|
53
|
+
|
54
|
+
if !config.stored?
|
55
|
+
raise RSimpy::UserNotProvidedError "Please configure RSimpy or supply username and password"
|
56
|
+
end
|
57
|
+
|
58
|
+
config.get
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
data/lib/user.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# user.rb : Encapsulates Simpy user account information
|
4
|
+
#
|
5
|
+
# Copyright April 2009, Jamal Hansen. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This is free software. Please see the LICENSE files for details.
|
8
|
+
module RSimpy
|
9
|
+
# The RSimpy::User class encapsulates user information.
|
10
|
+
#
|
11
|
+
# You can instanciate it with a hash containing login and password
|
12
|
+
#
|
13
|
+
# For example:
|
14
|
+
#
|
15
|
+
# user = RSimpy::User.new 'login', 'password'
|
16
|
+
|
17
|
+
class User
|
18
|
+
def initialize login, pass
|
19
|
+
@login = login
|
20
|
+
@pass = pass
|
21
|
+
end
|
22
|
+
|
23
|
+
def credentials
|
24
|
+
[@login, @pass]
|
25
|
+
end
|
26
|
+
|
27
|
+
def valid?
|
28
|
+
@login && @pass
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/rsimpy.gemspec
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rsimpy}
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jamal Hansen"]
|
12
|
+
s.date = %q{2009-12-22}
|
13
|
+
s.default_executable = %q{simp}
|
14
|
+
s.email = %q{jamal.hansen@gmail.com}
|
15
|
+
s.executables = ["simp"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".gitignore",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION.yml",
|
27
|
+
"bin/simp",
|
28
|
+
"features/links/adding_a_link.feature",
|
29
|
+
"features/links/querying_links.feature",
|
30
|
+
"features/links/steps/link_steps.rb",
|
31
|
+
"features/notes/query_note.feature",
|
32
|
+
"features/notes/remove_note.feature",
|
33
|
+
"features/notes/save_note.feature",
|
34
|
+
"features/notes/steps/note_steps.rb",
|
35
|
+
"features/support/env.rb",
|
36
|
+
"features/tags/merge_tags.feature",
|
37
|
+
"features/tags/querying_tags.feature",
|
38
|
+
"features/tags/remove_tag.feature",
|
39
|
+
"features/tags/rename_tag.feature",
|
40
|
+
"features/tags/split_tag.feature",
|
41
|
+
"features/tags/steps/tag_steps.rb",
|
42
|
+
"lib/base_service.rb",
|
43
|
+
"lib/client.rb",
|
44
|
+
"lib/configuration.rb",
|
45
|
+
"lib/errors/connection_error.rb",
|
46
|
+
"lib/errors/required_field_missing_error.rb",
|
47
|
+
"lib/errors/user_not_provided_error.rb",
|
48
|
+
"lib/links.rb",
|
49
|
+
"lib/parameters.rb",
|
50
|
+
"lib/posting_service.rb",
|
51
|
+
"lib/profile_storage_service.rb",
|
52
|
+
"lib/querying_service.rb",
|
53
|
+
"lib/rsimpy.rb",
|
54
|
+
"lib/user.rb",
|
55
|
+
"rsimpy.gemspec",
|
56
|
+
"test/client_test.rb",
|
57
|
+
"test/configuration_test.rb",
|
58
|
+
"test/deleting_service_test.rb",
|
59
|
+
"test/fixtures/test",
|
60
|
+
"test/fixtures/user_pass",
|
61
|
+
"test/links_test.rb",
|
62
|
+
"test/parameters_test.rb",
|
63
|
+
"test/posting_service_test.rb",
|
64
|
+
"test/profile_storage_service_test.rb",
|
65
|
+
"test/querying_service_test.rb",
|
66
|
+
"test/r_simpy_test.rb",
|
67
|
+
"test/required_field_missing_error_test.rb",
|
68
|
+
"test/responsive.rb",
|
69
|
+
"test/storage_builder.rb",
|
70
|
+
"test/storage_service_mock.rb",
|
71
|
+
"test/test_helper.rb",
|
72
|
+
"test/user_not_provided_error_test.rb",
|
73
|
+
"test/user_test.rb"
|
74
|
+
]
|
75
|
+
s.homepage = %q{http://github.com/rubyyot/rsimpy}
|
76
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
77
|
+
s.require_paths = ["lib"]
|
78
|
+
s.rubyforge_project = %q{rsimpy}
|
79
|
+
s.rubygems_version = %q{1.3.5}
|
80
|
+
s.summary = %q{API Wrapper for simpy.com}
|
81
|
+
s.test_files = [
|
82
|
+
"test/storage_service_mock.rb",
|
83
|
+
"test/parameters_test.rb",
|
84
|
+
"test/posting_service_test.rb",
|
85
|
+
"test/deleting_service_test.rb",
|
86
|
+
"test/test_helper.rb",
|
87
|
+
"test/storage_builder.rb",
|
88
|
+
"test/user_test.rb",
|
89
|
+
"test/links_test.rb",
|
90
|
+
"test/responsive.rb",
|
91
|
+
"test/client_test.rb",
|
92
|
+
"test/configuration_test.rb",
|
93
|
+
"test/user_not_provided_error_test.rb",
|
94
|
+
"test/required_field_missing_error_test.rb",
|
95
|
+
"test/querying_service_test.rb",
|
96
|
+
"test/profile_storage_service_test.rb",
|
97
|
+
"test/r_simpy_test.rb"
|
98
|
+
]
|
99
|
+
|
100
|
+
if s.respond_to? :specification_version then
|
101
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
102
|
+
s.specification_version = 3
|
103
|
+
|
104
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
105
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.4.2"])
|
106
|
+
s.add_runtime_dependency(%q<khayyam>, [">= 0.0.1"])
|
107
|
+
s.add_development_dependency(%q<cucumber>, [">= 0.3.11"])
|
108
|
+
s.add_development_dependency(%q<fakeweb>, [">= 1.2.3"])
|
109
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
110
|
+
s.add_development_dependency(%q<technicalpickles-jeweler>, [">= 0"])
|
111
|
+
else
|
112
|
+
s.add_dependency(%q<httparty>, [">= 0.4.2"])
|
113
|
+
s.add_dependency(%q<khayyam>, [">= 0.0.1"])
|
114
|
+
s.add_dependency(%q<cucumber>, [">= 0.3.11"])
|
115
|
+
s.add_dependency(%q<fakeweb>, [">= 1.2.3"])
|
116
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
117
|
+
s.add_dependency(%q<technicalpickles-jeweler>, [">= 0"])
|
118
|
+
end
|
119
|
+
else
|
120
|
+
s.add_dependency(%q<httparty>, [">= 0.4.2"])
|
121
|
+
s.add_dependency(%q<khayyam>, [">= 0.0.1"])
|
122
|
+
s.add_dependency(%q<cucumber>, [">= 0.3.11"])
|
123
|
+
s.add_dependency(%q<fakeweb>, [">= 1.2.3"])
|
124
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
125
|
+
s.add_dependency(%q<technicalpickles-jeweler>, [">= 0"])
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
data/test/client_test.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'fakeweb'
|
3
|
+
require 'errors/user_not_provided_error'
|
4
|
+
|
5
|
+
|
6
|
+
class ClientTest < Test::Unit::TestCase
|
7
|
+
should "get" do
|
8
|
+
FakeWeb.allow_net_connect = false
|
9
|
+
FakeWeb.register_uri("http://USERNAME:PASSWORD@www.simpy.com:80/simpy/api/rest/GetLinks.do", :string => get_response)
|
10
|
+
|
11
|
+
response = RSimpy::Client.new(RSimpy::User.new('USERNAME', 'PASSWORD')).get("/GetLinks.do")
|
12
|
+
|
13
|
+
assert response != nil
|
14
|
+
assert_equal Hash, response['links'].class
|
15
|
+
end
|
16
|
+
|
17
|
+
should "throw user not provided if user !valid?" do
|
18
|
+
begin
|
19
|
+
client = RSimpy::Client.new(InvalidUser.new)
|
20
|
+
flunk "should have thrown UserNotProvidedError"
|
21
|
+
rescue RSimpy::UserNotProvidedError => e
|
22
|
+
assert_equal RSimpy::UserNotProvidedError, e.class
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
should "throw user not provided if user nil" do
|
27
|
+
begin
|
28
|
+
client = RSimpy::Client.new(nil)
|
29
|
+
flunk "should have thrown UserNotProvidedError"
|
30
|
+
rescue RSimpy::UserNotProvidedError => e
|
31
|
+
assert_equal RSimpy::UserNotProvidedError, e.class
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class InvalidUser
|
37
|
+
def valid?
|
38
|
+
false
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'storage_builder'
|
3
|
+
require 'storage_service_mock'
|
4
|
+
|
5
|
+
class ConfigurationTest < Test::Unit::TestCase
|
6
|
+
should "detect stored configuration" do
|
7
|
+
config = RSimpy::Configuration.new StorageBuilder.new.with_stored_configuration('foo', 'bar').build
|
8
|
+
assert config.stored?
|
9
|
+
end
|
10
|
+
|
11
|
+
should "detect missing configuration" do
|
12
|
+
config = RSimpy::Configuration.new StorageBuilder.new.without_stored_configuration.build
|
13
|
+
assert !config.stored?
|
14
|
+
end
|
15
|
+
|
16
|
+
should "save user info" do
|
17
|
+
storage_service = StorageBuilder.new.without_stored_configuration.build
|
18
|
+
config = RSimpy::Configuration.new storage_service
|
19
|
+
config.user = RSimpy::User.new('foo', 'bar')
|
20
|
+
|
21
|
+
assert config.save
|
22
|
+
login, pass = storage_service.user.credentials
|
23
|
+
assert_equal 'foo', login
|
24
|
+
assert_equal 'bar', pass
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'cgi'
|
3
|
+
require 'errors/required_field_missing_error'
|
4
|
+
|
5
|
+
class LinkDeletingServiceCanDelete < Test::Unit::TestCase
|
6
|
+
context "deleting" do
|
7
|
+
setup do
|
8
|
+
FakeWeb.clean_registry
|
9
|
+
FakeWeb.allow_net_connect = false
|
10
|
+
|
11
|
+
@client = RSimpy::Client.new(RSimpy::User.new("USERNAME","PASSWORD"))
|
12
|
+
@action = "/DeleteLink.do?"
|
13
|
+
end
|
14
|
+
|
15
|
+
should "build basic link" do
|
16
|
+
params = RSimpy::Parameters.new(:href => "http://www.example.com")
|
17
|
+
link = RSimpy::PostingService.new(RSimpy::DELETE_LINK,
|
18
|
+
@client).build_link(params)
|
19
|
+
assert(/#{@action}/ =~ link)
|
20
|
+
end
|
21
|
+
|
22
|
+
should "delete" do
|
23
|
+
FakeWeb.register_uri(:post, "http://USERNAME:PASSWORD@www.simpy.com:80/simpy/api/rest/DeleteLink.do?href=http%3A%2F%2Fwww.example.com&src=rsimpy", :string => delete_response)
|
24
|
+
|
25
|
+
service = RSimpy::PostingService.new(RSimpy::DELETE_LINK, @client)
|
26
|
+
response = service.execute RSimpy::Parameters.new(:href => "http://www.example.com")
|
27
|
+
assert service.success
|
28
|
+
assert_equal Hash, response.class
|
29
|
+
end
|
30
|
+
|
31
|
+
should "set src" do
|
32
|
+
params = RSimpy::Parameters.new(:href => "http://www.example.com")
|
33
|
+
link = RSimpy::PostingService.new(RSimpy::DELETE_LINK, @client).build_link(params)
|
34
|
+
assert(/src=rsimpy/ =~ link)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "link deleting service responses" do
|
39
|
+
should "have a successful response" do
|
40
|
+
FakeWeb.register_uri(:post, "http://USERNAME:PASSWORD@www.simpy.com:80/simpy/api/rest/DeleteLink.do?href=http%3A%2F%2Fexample.com&src=rsimpy", :string => delete_response)
|
41
|
+
|
42
|
+
client = RSimpy::Client.new(RSimpy::User.new("USERNAME","PASSWORD"))
|
43
|
+
service = RSimpy::PostingService.new(RSimpy::DELETE_LINK, client)
|
44
|
+
|
45
|
+
response = service.execute RSimpy::Parameters.new :href => "http://example.com"
|
46
|
+
assert service.success
|
47
|
+
assert_equal "0", service.status_code
|
48
|
+
assert_equal "Link deleted successfully.", service.status_message
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|