whereistand 0.0.2 → 0.0.3

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/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.0.3. implemented account, issue, and opinion services, all unit tests succeeding
2
+
1
3
  v0.0.2. revising accessibility and naming conventions
2
4
 
3
5
  v0.0.1. initial release
data/Gemfile CHANGED
@@ -2,10 +2,6 @@ source "http://rubygems.org"
2
2
 
3
3
  gem "yajl-ruby"
4
4
 
5
- group :development do
6
- gem "parka"
7
- end
8
-
9
5
  group :test do
10
6
  gem "rspec"
11
7
  end
data/Manifest CHANGED
@@ -3,9 +3,12 @@ Gemfile
3
3
  Gemfile.lock
4
4
  LICENSE
5
5
  Manifest
6
- README
6
+ README.rdoc
7
7
  Rakefile
8
- lib/client/access.rb
8
+ lib/client/accounts.rb
9
+ lib/client/issues.rb
10
+ lib/client/opinions.rb
11
+ lib/client/tools.rb
9
12
  lib/dom/account.rb
10
13
  lib/dom/account_issues.rb
11
14
  lib/dom/account_results.rb
@@ -21,4 +24,6 @@ lib/dom/results.rb
21
24
  lib/dom/unknown_opinion.rb
22
25
  lib/dom/unverified_opinion.rb
23
26
  lib/whereistand.rb
24
- spec/client_access_spec.rb
27
+ spec/client_accounts_spec.rb
28
+ spec/client_issues_spec.rb
29
+ spec/client_opinions_spec.rb
@@ -0,0 +1,17 @@
1
+ =whereIstand Ruby SDK
2
+
3
+ The whereIstand Ruby SDK allows developers to interface with whereIstand opinion data through a series of library that encapsulates the whereIstand API service calls and adapt them into objects for your convenience.
4
+
5
+ =Installation
6
+
7
+ sudo gem install whereistand
8
+
9
+ =Examples
10
+
11
+ # Does an account search that returns AccountResults.
12
+ # Refer to source for object structure
13
+ results = WIS::Client::Access.account_search("bill")
14
+ puts "Hits: " + results.hits
15
+ results.accounts.each do |account|
16
+ puts account.name + " - " + account.description
17
+ end
@@ -0,0 +1,26 @@
1
+ class WIS::Client::Accounts
2
+
3
+ def self.search(string)
4
+ string = WIS::Client::Tools.uri_escape(string)
5
+ results = WIS::Client::Tools.get_json("http://api.whereistand.com/accounts?search=" + string)
6
+ WIS::DOM::AccountResults.adapt_json(results)
7
+ end
8
+
9
+ def self.find_by_id(id)
10
+ WIS::DOM::Account.adapt_json(WIS::Client::Tools.get_json("http://api.whereistand.com/accounts/" + id.to_s))
11
+ end
12
+
13
+ def self.find_by_id_array(ids)
14
+ result = WIS::Client::Tools.get_json("http://api.whereistand.com/accounts?ids=" + ids.join(","))
15
+ WIS::DOM::Account.adapt_json(result)
16
+ end
17
+
18
+ def self.find_by_name(name)
19
+ WIS::DOM::Account.adapt_json(WIS::Client::Tools.get_json("http://api.whereistand.com/accounts/" + name))
20
+ end
21
+
22
+ def self.find_by_name_array(names)
23
+ result = WIS::Client::Tools.get_json("http://api.whereistand.com/accounts?names=" + names.join(","))
24
+ WIS::DOM::Account.adapt_json(result)
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ class WIS::Client::Issues
2
+ def self.search(string)
3
+ string = WIS::Client::Tools.uri_escape(string)
4
+ results = WIS::Client::Tools.get_json("http://api.whereistand.com/issues?search=" + string)
5
+ WIS::DOM::IssueResults.adapt_json(results)
6
+ end
7
+
8
+ def self.find_by_id(id)
9
+ WIS::DOM::Issue.adapt_json(WIS::Client::Tools.get_json("http://api.whereistand.com/issues/" + id.to_s))
10
+ end
11
+
12
+ def self.find_by_id_array(ids)
13
+ result = WIS::Client::Tools.get_json("http://api.whereistand.com/issues?ids=" + ids.join(","))
14
+ WIS::DOM::Issue.adapt_json(result)
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ class WIS::Client::Opinions
2
+
3
+ def self.find_by_account_id_and_issue_id(account_id, issue_id)
4
+ results = WIS::Client::Tools.get_json("http://api.whereistand.com/opinions?account=" + account_id.to_s + "&issue=" + issue_id.to_s)
5
+ WIS::DOM::Opinion.adapt_json(results)
6
+ end
7
+
8
+ def self.search_known_account_by_issue(account, string)
9
+ string = WIS::Client::Tools.uri_escape(string)
10
+ results = WIS::Client::Tools.get_json("http://api.whereistand.com/opinions?account=" + account.id.to_s + "&issue=" + string)
11
+ WIS::DOM::AccountIssues.adapt_json(results)
12
+ end
13
+
14
+ end
@@ -0,0 +1,10 @@
1
+ class WIS::Client::Tools
2
+ def self.get_json(url)
3
+ resp = Net::HTTP.get_response(URI.parse(url))
4
+ Yajl::Parser.parse(resp.body)
5
+ end
6
+
7
+ def self.uri_escape(string)
8
+ URI.escape(string, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
9
+ end
10
+ end
@@ -1,10 +1,22 @@
1
1
  class WIS::DOM::Account
2
- attr_reader :id, :name;
3
- attr_accessor :description;
2
+ attr_reader :id, :name
3
+ attr_accessor :description
4
4
 
5
5
  def initialize(id, name, description)
6
- @id = id;
7
- @name = name;
8
- @description = description;
6
+ @id = id
7
+ @name = name
8
+ @description = description
9
+ end
10
+
11
+ def self.adapt_json(data)
12
+ if data.kind_of?(Array)
13
+ accounts = []
14
+ data.each do |a|
15
+ accounts << WIS::DOM::Account.new(a["ID"], a["Name"], a["Description"])
16
+ end
17
+ accounts
18
+ else
19
+ WIS::DOM::Account.new(data["ID"], data["Name"], data["Description"])
20
+ end
9
21
  end
10
22
  end
@@ -1,9 +1,21 @@
1
1
  class WIS::DOM::Issue
2
- attr_reader :id;
3
- attr_accessor :description;
2
+ attr_reader :id
3
+ attr_accessor :description
4
4
 
5
5
  def initialize(id, description)
6
- @id = id;
7
- @description = description;
6
+ @id = id
7
+ @description = description
8
+ end
9
+
10
+ def self.adapt_json(data)
11
+ if data.kind_of?(Array)
12
+ issues = []
13
+ data.each do |i|
14
+ issues << WIS::DOM::Issue.new(i["ID"], i["Description"])
15
+ end
16
+ issues
17
+ else
18
+ WIS::DOM::Issue.new(data["ID"], data["Description"])
19
+ end
8
20
  end
9
21
  end
@@ -5,4 +5,13 @@ class WIS::DOM::IssueResults < WIS::DOM::Results
5
5
  super(hits)
6
6
  @issues = issues
7
7
  end
8
+
9
+ def self.adapt_json(data)
10
+ issues = []
11
+ data["Issues"].each do |i|
12
+ issues << WIS::DOM::Issue.new(i["ID"], i["Description"])
13
+ end
14
+
15
+ WIS::DOM::IssueResults.new(data["Hits"], issues)
16
+ end
8
17
  end
@@ -5,4 +5,10 @@ class WIS::DOM::Opinion
5
5
  @account = account
6
6
  @issue = issue
7
7
  end
8
+
9
+ def self.adapt_json(data)
10
+ account = WIS::DOM::Account.new(data["Account"]["ID"], data["Account"]["Name"], data["Account"]["Description"])
11
+ issue = WIS::DOM::Issue.new(data["Issue"]["ID"], data["Issue"]["Description"])
12
+ WIS::DOM::Opinion.new(account, issue)
13
+ end
8
14
  end
@@ -1,5 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
+ require 'uri'
4
+ require 'net/http'
3
5
  require 'yajl'
4
6
 
5
7
  module WIS; module DOM; end; module Client; end; end
@@ -21,4 +23,7 @@ require 'dom/issue_accounts'
21
23
  require 'dom/issue_results'
22
24
  require 'dom/issue_result'
23
25
 
24
- require 'client/access'
26
+ require 'client/tools'
27
+ require 'client/accounts'
28
+ require 'client/issues'
29
+ require 'client/opinions'
@@ -0,0 +1,43 @@
1
+ require 'lib/whereistand'
2
+
3
+ describe WIS::Client::Accounts do
4
+
5
+ it "search should return results" do
6
+ results = WIS::Client::Accounts.search("clinton")
7
+ results.kind_of?(WIS::DOM::AccountResults).should be_true
8
+ results.hits.should > 0
9
+ end
10
+
11
+ it "find by id should work" do
12
+ results = WIS::Client::Accounts.find_by_id(196)
13
+ results.should_not be_nil
14
+ results.kind_of?(WIS::DOM::Account).should be_true
15
+ results.id.should == 196
16
+ end
17
+
18
+ it "find by id array should work" do
19
+ results = WIS::Client::Accounts.find_by_id_array([196, 5874])
20
+ results.should_not be_nil
21
+ results.length.should == 2
22
+ results.each do |account|
23
+ account.kind_of?(WIS::DOM::Account).should be_true
24
+ end
25
+ end
26
+
27
+ it "find by name should work" do
28
+ results = WIS::Client::Accounts.find_by_name("brianr")
29
+ results.should_not be_nil
30
+ results.kind_of?(WIS::DOM::Account).should be_true
31
+ results.id.should == 196
32
+ end
33
+
34
+ it "find by name array should work" do
35
+ results = WIS::Client::Accounts.find_by_name_array(["brianr", "nick"])
36
+ results.should_not be_nil
37
+ results.length.should == 2
38
+ results.each do |account|
39
+ account.kind_of?(WIS::DOM::Account).should be_true
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,27 @@
1
+ require 'lib/whereistand'
2
+
3
+ describe WIS::Client::Issues do
4
+
5
+ it "search should return results" do
6
+ results = WIS::Client::Issues.search("global warming")
7
+ results.kind_of?(WIS::DOM::IssueResults).should be_true
8
+ results.hits.should > 0
9
+ end
10
+
11
+ it "find by id should work" do
12
+ results = WIS::Client::Issues.find_by_id(16400)
13
+ results.should_not be_nil
14
+ results.kind_of?(WIS::DOM::Issue).should be_true
15
+ results.id.should == 16400
16
+ end
17
+
18
+ it "find by id array should work" do
19
+ results = WIS::Client::Issues.find_by_id_array([16400, 4662])
20
+ results.should_not be_nil
21
+ results.length.should == 2
22
+ results.each do |issue|
23
+ issue.kind_of?(WIS::DOM::Issue).should be_true
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,18 @@
1
+ require 'lib/whereistand'
2
+
3
+ describe WIS::Client::Opinions do
4
+
5
+ it "find opinion by account id and issue id should work" do
6
+ opinion = WIS::Client::Opinions.find_by_account_id_and_issue_id(196, 16400)
7
+ opinion.should_not be_nil
8
+ opinion.kind_of?(WIS::DOM::Opinion).should be_true
9
+ end
10
+
11
+ it "known account search by issue should return results" do
12
+ account = WIS::DOM::Account.new(196, "brianr", "BrianR")
13
+ results = WIS::Client::Opinions.search_known_account_by_issue(account, "global warming")
14
+ results.kind_of?(WIS::DOM::AccountIssues).should be_true
15
+ results.hits.should > 0
16
+ end
17
+
18
+ end
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{whereistand}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["whereIstand"]
9
- s.date = %q{2010-10-28}
9
+ s.date = %q{2010-10-30}
10
10
  s.description = %q{whereIstand Ruby SDK}
11
11
  s.email = %q{help@whereistand.com}
12
- s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/client/access.rb", "lib/dom/account.rb", "lib/dom/account_issues.rb", "lib/dom/account_results.rb", "lib/dom/approved_opinion.rb", "lib/dom/evidenced_opinion.rb", "lib/dom/expressed_opinion.rb", "lib/dom/issue.rb", "lib/dom/issue_accounts.rb", "lib/dom/issue_result.rb", "lib/dom/issue_results.rb", "lib/dom/opinion.rb", "lib/dom/results.rb", "lib/dom/unknown_opinion.rb", "lib/dom/unverified_opinion.rb", "lib/whereistand.rb"]
13
- s.files = ["CHANGELOG", "Gemfile", "Gemfile.lock", "LICENSE", "Manifest", "README", "Rakefile", "lib/client/access.rb", "lib/dom/account.rb", "lib/dom/account_issues.rb", "lib/dom/account_results.rb", "lib/dom/approved_opinion.rb", "lib/dom/evidenced_opinion.rb", "lib/dom/expressed_opinion.rb", "lib/dom/issue.rb", "lib/dom/issue_accounts.rb", "lib/dom/issue_result.rb", "lib/dom/issue_results.rb", "lib/dom/opinion.rb", "lib/dom/results.rb", "lib/dom/unknown_opinion.rb", "lib/dom/unverified_opinion.rb", "lib/whereistand.rb", "spec/client_access_spec.rb", "whereistand.gemspec"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "lib/client/accounts.rb", "lib/client/issues.rb", "lib/client/opinions.rb", "lib/client/tools.rb", "lib/dom/account.rb", "lib/dom/account_issues.rb", "lib/dom/account_results.rb", "lib/dom/approved_opinion.rb", "lib/dom/evidenced_opinion.rb", "lib/dom/expressed_opinion.rb", "lib/dom/issue.rb", "lib/dom/issue_accounts.rb", "lib/dom/issue_result.rb", "lib/dom/issue_results.rb", "lib/dom/opinion.rb", "lib/dom/results.rb", "lib/dom/unknown_opinion.rb", "lib/dom/unverified_opinion.rb", "lib/whereistand.rb"]
13
+ s.files = ["CHANGELOG", "Gemfile", "Gemfile.lock", "LICENSE", "Manifest", "README.rdoc", "Rakefile", "lib/client/accounts.rb", "lib/client/issues.rb", "lib/client/opinions.rb", "lib/client/tools.rb", "lib/dom/account.rb", "lib/dom/account_issues.rb", "lib/dom/account_results.rb", "lib/dom/approved_opinion.rb", "lib/dom/evidenced_opinion.rb", "lib/dom/expressed_opinion.rb", "lib/dom/issue.rb", "lib/dom/issue_accounts.rb", "lib/dom/issue_result.rb", "lib/dom/issue_results.rb", "lib/dom/opinion.rb", "lib/dom/results.rb", "lib/dom/unknown_opinion.rb", "lib/dom/unverified_opinion.rb", "lib/whereistand.rb", "spec/client_accounts_spec.rb", "spec/client_issues_spec.rb", "spec/client_opinions_spec.rb", "whereistand.gemspec"]
14
14
  s.homepage = %q{http://github.com/whereIstand/ruby-sdk}
15
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Whereistand", "--main", "README"]
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Whereistand", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = %q{whereistand}
18
18
  s.rubygems_version = %q{1.3.7}
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whereistand
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - whereIstand
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-28 00:00:00 -04:00
18
+ date: 2010-10-30 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -69,8 +69,11 @@ extensions: []
69
69
  extra_rdoc_files:
70
70
  - CHANGELOG
71
71
  - LICENSE
72
- - README
73
- - lib/client/access.rb
72
+ - README.rdoc
73
+ - lib/client/accounts.rb
74
+ - lib/client/issues.rb
75
+ - lib/client/opinions.rb
76
+ - lib/client/tools.rb
74
77
  - lib/dom/account.rb
75
78
  - lib/dom/account_issues.rb
76
79
  - lib/dom/account_results.rb
@@ -92,9 +95,12 @@ files:
92
95
  - Gemfile.lock
93
96
  - LICENSE
94
97
  - Manifest
95
- - README
98
+ - README.rdoc
96
99
  - Rakefile
97
- - lib/client/access.rb
100
+ - lib/client/accounts.rb
101
+ - lib/client/issues.rb
102
+ - lib/client/opinions.rb
103
+ - lib/client/tools.rb
98
104
  - lib/dom/account.rb
99
105
  - lib/dom/account_issues.rb
100
106
  - lib/dom/account_results.rb
@@ -110,7 +116,9 @@ files:
110
116
  - lib/dom/unknown_opinion.rb
111
117
  - lib/dom/unverified_opinion.rb
112
118
  - lib/whereistand.rb
113
- - spec/client_access_spec.rb
119
+ - spec/client_accounts_spec.rb
120
+ - spec/client_issues_spec.rb
121
+ - spec/client_opinions_spec.rb
114
122
  - whereistand.gemspec
115
123
  has_rdoc: true
116
124
  homepage: http://github.com/whereIstand/ruby-sdk
@@ -123,7 +131,7 @@ rdoc_options:
123
131
  - --title
124
132
  - Whereistand
125
133
  - --main
126
- - README
134
+ - README.rdoc
127
135
  require_paths:
128
136
  - lib
129
137
  required_ruby_version: !ruby/object:Gem::Requirement
data/README DELETED
File without changes
@@ -1,13 +0,0 @@
1
- class WIS::Client::Access
2
-
3
- def self.account_search(string)
4
- # invoke call to http://api.whereistand.com/account/search?q=blah
5
- value = "{\"Accounts\":[{\"ID\":380,\"Name\":\"BillClinton\",\"Description\":\"Bill Clinton\"},{\"ID\":120,\"Name\":\"HillaryClinton\",\"Description\":\"Hillary Rodham Clinton\"},{\"ID\":3340,\"Name\":\"ChelseaClinton\",\"Description\":\"Chelsea Clinton\"}],\"Hits\":3}"
6
- WIS::DOM::AccountResults.adapt_json(Yajl::Parser.parse(value))
7
- end
8
-
9
- def self.account_issues_search(account, string)
10
- value = "{\"Account\":{\"ID\":1,\"Name\":\"BillClinton\",\"Description\":\"William Jefferson Clinton\"},\"Issues\":[{\"Issue\":{\"ID\":1,\"Description\":\"Is global warming cool?\"},\"Unknown\":null,\"Unverified\":null,\"Approved\":{\"Account\":{\"ID\":1,\"Name\":\"BillClinton\",\"Description\":\"William Jefferson Clinton\"},\"Issue\":{\"ID\":1,\"Description\":\"Is global warming cool?\"}}},{\"Issue\":{\"ID\":2,\"Description\":\"Is global warming awesome?\"},\"Unknown\":{\"Account\":null,\"Issue\":{\"ID\":2,\"Description\":\"Is global warming awesome?\"}},\"Unverified\":null,\"Approved\":null},{\"Issue\":{\"ID\":3,\"Description\":\"Is global warming raspy?\"},\"Unknown\":{\"Account\":null,\"Issue\":{\"ID\":3,\"Description\":\"Is global warming raspy?\"}},\"Unverified\":null,\"Approved\":null}],\"Hits\":3}"
11
- WIS::DOM::AccountIssues.adapt_json(Yajl::Parser.parse(value))
12
- end
13
- end
@@ -1,20 +0,0 @@
1
- require 'lib/whereistand'
2
-
3
- describe WIS::Client::Access do
4
-
5
- it "account search should not fail" do
6
- WIS::Client::Access.account_search("bill clinton")
7
- end
8
-
9
- it "account issues search should not fail" do
10
- account = WIS::DOM::Account.new(1, "BillClinton", "Bill Clinton")
11
- WIS::Client::Access.account_issues_search(account, "global warming")
12
- end
13
-
14
- it "should do this just for me" do
15
- Dir["**/*"].select do |d|
16
- puts d
17
- end
18
- end
19
-
20
- end