knodes 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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NTc2YjYwYzJjNzA1NzQyNWFjODEwMGE5M2Y1YTY5OGRjMjVmMGYxZA==
5
+ data.tar.gz: !binary |-
6
+ OGZmMDFmNTdmN2QxYjIzZjBjODBiNjAwMWY5NDRlZDdjYTFkMjBkMw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OTU1ZmMxNjkwNTc4ZmExZWRmYmMzOTdkNjZiZDQwY2FjNzA3NmE4YWE1Yzc5
10
+ MDU2NmU4ZjU2NDkwZDhiNjJlNGRmODFjZmMwYjZiY2UxMDJlYWNiNTA0NDcz
11
+ ZjJhMGY0MWY5NDcyMDc4MzBkMWRjOGFiYWNiNjRjM2Y2MzU3NTE=
12
+ data.tar.gz: !binary |-
13
+ ZjM2NGY5YWQ2N2ZkZGQ5NWRjNzE0ZDgxNWY2YzQ0NjA5YzZkNmY3MGMyMTM5
14
+ NGVhMGY2YzkyOWVmNzA2ZjE1YTU3MmQ2MjdlYTcyYzMwNzE2ZmRlZGNjYmY2
15
+ ZTlmZjZhMTMxZjI5MzM1NmE2MDk5N2FhZjQzODM3MWJhZDdmMzc=
data/.env ADDED
@@ -0,0 +1,14 @@
1
+ # EXAMPLE ENV FILE
2
+
3
+ CUSTOMER_ID=customer_id
4
+ CUSTOMER_SECRET=customer_secret
5
+ TEST_APP_ID=test_app_id
6
+ TEST_APP_SECRET=test_app_secret
7
+ TEST_USER_ID=test_user_id
8
+ TEST_NETWORK_ID=test_network_id
9
+ TEST_NETWORK_TOKEN=test_network_token
10
+ TEST_PERSON_ID=test_person_id
11
+ TEST_DOC_ID=test_doc_id
12
+ TEST_LOCATION_ID=test_location_id
13
+ TEST_COMPANY_ID=test_company_id
14
+ TEST_SCHOOL_ID=test_school_id
@@ -0,0 +1,6 @@
1
+
2
+ spec/.DS_Store
3
+
4
+ .DS_Store
5
+
6
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source :rubygems
2
+
3
+ gem 'faraday'
4
+ gem 'faraday_middleware'
5
+ gem 'hashie'
6
+
7
+ group :development do
8
+ gem 'guard'
9
+ gem 'rb-fsevent'
10
+ gem 'growl'
11
+ gem 'guard-bundler'
12
+ gem 'guard-rspec'
13
+ gem 'guard-cucumber'
14
+ end
15
+
16
+ group :development, :test do
17
+ gem 'cucumber'
18
+ gem 'rspec'
19
+ gem 'dotenv'
20
+ end
21
+
@@ -0,0 +1,59 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ builder (3.1.4)
5
+ cucumber (1.2.1)
6
+ builder (>= 2.1.2)
7
+ diff-lcs (>= 1.1.3)
8
+ gherkin (~> 2.11.0)
9
+ json (>= 1.4.6)
10
+ diff-lcs (1.1.3)
11
+ faraday (0.8.4)
12
+ multipart-post (~> 1.1)
13
+ faraday_middleware (0.8.8)
14
+ faraday (>= 0.7.4, < 0.9)
15
+ gherkin (2.11.5)
16
+ json (>= 1.4.6)
17
+ growl (1.0.3)
18
+ guard (1.4.0)
19
+ listen (>= 0.4.2)
20
+ thor (>= 0.14.6)
21
+ guard-bundler (1.0.0)
22
+ bundler (~> 1.0)
23
+ guard (~> 1.1)
24
+ guard-cucumber (1.2.0)
25
+ cucumber (>= 1.2.0)
26
+ guard (>= 1.1.0)
27
+ guard-rspec (2.1.0)
28
+ guard (>= 1.1)
29
+ rspec (~> 2.11)
30
+ hashie (1.2.0)
31
+ json (1.7.5)
32
+ listen (0.5.3)
33
+ multipart-post (1.1.5)
34
+ rb-fsevent (0.9.2)
35
+ rspec (2.11.0)
36
+ rspec-core (~> 2.11.0)
37
+ rspec-expectations (~> 2.11.0)
38
+ rspec-mocks (~> 2.11.0)
39
+ rspec-core (2.11.1)
40
+ rspec-expectations (2.11.3)
41
+ diff-lcs (~> 1.1.3)
42
+ rspec-mocks (2.11.3)
43
+ thor (0.16.0)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ cucumber
50
+ faraday
51
+ faraday_middleware
52
+ growl
53
+ guard
54
+ guard-bundler
55
+ guard-cucumber
56
+ guard-rspec
57
+ hashie
58
+ rb-fsevent
59
+ rspec
@@ -0,0 +1,16 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'bundler' do
5
+ watch('Gemfile')
6
+ # Uncomment next line if Gemfile contain `gemspec' command
7
+ # watch(/^.+\.gemspec/)
8
+ end
9
+
10
+ guard 'rspec', :cli => "--color --format doc" do
11
+ watch(%r{^spec/.+_spec\.rb$})
12
+ #watch(%r{^lib/(.+)\.rb$}) { |m| puts m.inspect }
13
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
14
+ watch('spec/spec_helper.rb') { "spec/" }
15
+ watch('lib/knodes.rb.') { "spec/" }
16
+ end
@@ -0,0 +1,81 @@
1
+ #Knodes Ruby Client Library
2
+
3
+ A ruby client library for the Knodes API
4
+ See full API documentation at http://developer.kno.des/
5
+
6
+ ## Usage
7
+
8
+ ### Installation
9
+
10
+ Install the gem:
11
+ ```gem install knodes-client```
12
+ or, add it to your Gemfile:
13
+ ```gem 'knodes-client'```
14
+ ```bundle install```
15
+
16
+ ###Configuration
17
+ ```ruby
18
+ Knodes.configure do |config|
19
+ config.customer_id = "foo"
20
+ config.customer_secret = "bar"
21
+ end
22
+ ```
23
+
24
+ ###Examples
25
+
26
+ Get the customer details
27
+ ```response = Knodes.customer```
28
+
29
+ Search for a person
30
+ ```response = Knodes.people_search(:user_id=>user_id, :person_id=>"self", :q=>"Joe Schmoe")```
31
+
32
+ Get a person's details
33
+ ```response = Knodes.person(:user_id=>user_id, :person_id=>person_id)```
34
+
35
+ Search for a location
36
+ ```response = Knodes.locations_search(:user_id=>user_id, :q=>"New York")```
37
+
38
+ ## Motivation
39
+
40
+ Discovered Knodes at the 2012 TechCrunch Hackathon, won the API prize for the YourQ project. After changing the name to Que.io, we discovered that we needed a better client library, so I built it. Gained inspiration from the client libraries for Podio and Instagram.
41
+
42
+ ## Knodes API Reference
43
+
44
+ View the getting started guide here:
45
+ http://developer.knod.es/getting_started
46
+
47
+ View the API docs here:
48
+ http://developer.knod.es/docs
49
+
50
+ ## Tests
51
+
52
+ The tests rely on sample data from your social networks.
53
+ Sign up for an account here:
54
+ https://api.knod.es/portal/signup
55
+
56
+ Then, use the test harness to get your customer data. From there you can use this client to get the rest of the sample data.
57
+ Put your sample data into .env (sample file provided)
58
+ Then, to run the tests, you can use Guard for autotesting, or just vanilla Rspec:
59
+
60
+ ```bundle exec guard```
61
+
62
+ ## Contributors
63
+
64
+ If you discover a bug or want to contribute extra functionality:
65
+
66
+ 1. Fork it.
67
+ 2. Create a branch (`git checkout -b feature_or_bug_branch`)
68
+ 3. Commit your changes (`git commit -am "Added feature, fixed bug"`)
69
+ 4. Push to the branch (`git push origin feature_or_bug_branch`)
70
+ 5. Open a Pull Request
71
+ 6. ...
72
+ 7. Profit
73
+
74
+ ## License
75
+
76
+ This client library is released under the Apache license, Version 2.0
77
+ http://www.apache.org/licenses/LICENSE-2.0.html
78
+
79
+ Knodes and all other trademarks are © 2013 SnapGoods, Inc. All Rights Reserved.
80
+ http://knod.es/content/tos.pdf
81
+ http://knod.es/content/customer_agreement.pdf
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "knodes"
6
+ s.rubyforge_project = s.name
7
+ s.version = Knodes::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Matt Anderson"]
10
+ s.email = ["matthewrossanderson@gmail.com"]
11
+ s.homepage = "http://developer.knod.es/"
12
+ s.summary = %q{A ruby client library for the Knodes API}
13
+ s.description = %q{See API documentation at http://developer.knod.es/}
14
+ s.license = "Apache 2.0"
15
+ s.post_install_message =<<eos
16
+ ********************************************************************************
17
+
18
+ Thanks for installing the Knodes client library!
19
+
20
+ See API documentation at http://developer.knod.es/
21
+
22
+ There's always money in the banana stand.
23
+
24
+ ********************************************************************************
25
+ eos
26
+
27
+ s.add_development_dependency "rspec", "~>2.5.0"
28
+ s.add_runtime_dependency "faraday"
29
+ s.add_runtime_dependency "faraday_middleware"
30
+
31
+ s.files = `git ls-files`.split("\n")
32
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
33
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
34
+ s.require_paths = ["lib"]
35
+ end
@@ -0,0 +1,23 @@
1
+ require 'faraday'
2
+ require File.expand_path('../../knodes/error', __FILE__)
3
+
4
+ module FaradayMiddleware
5
+ class KnodesErrors < Faraday::Middleware
6
+ def call(env)
7
+ @app.call(env).on_complete do |response|
8
+ case response[:status].to_i
9
+ when 400
10
+ raise Knodes::BadRequest, response[:body]
11
+ #puts "#{finished_env[:body] if finished_env[:body]}"
12
+ when 404
13
+ raise Knodes::NotFound, response[:body]
14
+ #puts "#{finished_env if finished_env[:body]}"
15
+ end
16
+ end
17
+ end
18
+ def initialize(app)
19
+ super app
20
+ @parser = nil
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ require File.expand_path('../knodes/configuration', __FILE__)
5
+ require File.expand_path('../knodes/connection', __FILE__)
6
+ require File.expand_path('../knodes/request', __FILE__)
7
+ require File.expand_path('../knodes/client', __FILE__)
8
+
9
+ module Knodes
10
+ extend Configuration
11
+
12
+ #Knodes module methods#
13
+
14
+ # Alias for Knodes::Client.new
15
+ def self.client(options={})
16
+ Knodes::Client.new(options)
17
+ end
18
+
19
+ # Delegate to Knodes::Client
20
+ def self.method_missing(method, *args, &block)
21
+ return super unless client.respond_to?(method)
22
+ client.send(method, *args, &block)
23
+ end
24
+
25
+ # Delegate to Knodes::Client
26
+ def self.respond_to?(method)
27
+ return client.respond_to?(method) || super
28
+ end
29
+ end
@@ -0,0 +1,35 @@
1
+ module Knodes
2
+ class Client
3
+
4
+ Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}
5
+
6
+ # Creates a new client and sets configuration to passed options or their default values
7
+ def initialize(options={})
8
+ options = Knodes.options.merge(options)
9
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
10
+ send("#{key}=", options[key])
11
+ end
12
+ end
13
+
14
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
15
+
16
+ #convenience method for returning id/secret
17
+ def creds
18
+ Hash["customer_id" => customer_id, "customer_secret" => customer_secret]
19
+ end
20
+
21
+ include Connection
22
+ include Request
23
+
24
+ #here comes the good stuff.
25
+ #these refer to modules separated by Knodes resources, containing methods for each api call
26
+
27
+ include Customers
28
+ include Users
29
+ include People
30
+ include Documents
31
+ include Locations
32
+ include Companies
33
+ include Schools
34
+ end
35
+ end
@@ -0,0 +1,17 @@
1
+ module Knodes
2
+ class Client
3
+ module Companies
4
+ def company(options={})
5
+ response = get("companies/#{options[:company_id]}", options.merge(creds))
6
+ end
7
+
8
+ def companies_search(options={})
9
+ response = get("companies/search", options.merge(creds))
10
+ end
11
+
12
+ def company_people(options={})
13
+ response = get("companies/#{options[:company_id]}/people", options.merge(creds))
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Knodes
2
+ class Client
3
+ module Customers
4
+ def customer
5
+ response = get("customers", creds)
6
+ end
7
+
8
+ def customer_connect(options={})
9
+ response = post("customers/#{options[:customer_id]}/connect", options = options.merge(creds))
10
+ end
11
+
12
+ def customer_disconnect(options={})
13
+ response = post("customers/#{options[:customer_id]}/disconnect", options = options.merge(creds))
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ module Knodes
2
+ class Client
3
+ module Documents
4
+ def document(options={})
5
+ response = get("documents/#{options[:doc_id]}", options.merge(creds))
6
+ end
7
+
8
+ def documents_search(options={})
9
+ response = get("documents/search", options.merge(creds))
10
+ end
11
+
12
+ def document_people(options={})
13
+ response = get("documents/#{options[:doc_id]}/people", options.merge(creds))
14
+ end
15
+
16
+ def document_locations(options={})
17
+ response = get("documents/#{options[:doc_id]}/locations", options.merge(creds))
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Knodes
2
+ class Client
3
+ module Locations
4
+ def location(options={})
5
+ response = get("locations/#{options[:location_id]}", options.merge(creds))
6
+ end
7
+
8
+ def locations_search(options={})
9
+ response = get("locations/search", options.merge(creds))
10
+ end
11
+
12
+ def location_people(options={})
13
+ response = get("locations/#{options[:location_id]}/people", options.merge(creds))
14
+ end
15
+
16
+ def location_documents(options={})
17
+ response = get("locations/#{options[:location_id]}/documents", options.merge(creds))
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,35 @@
1
+ module Knodes
2
+ class Client
3
+ module People
4
+ def person(options={})
5
+ response = get("people/#{options[:person_id]}", options.merge(creds))
6
+ end
7
+
8
+ def people_search(options={})
9
+ options.merge!({ :type=> "people" })
10
+ response = get("people/search", options.merge(creds))
11
+ end
12
+
13
+ def person_people(options={})
14
+ options.merge!({:type=>"people", :q=>""})
15
+ response = get("search", options.merge(creds))
16
+ end
17
+
18
+ def person_documents(options={})
19
+ response = get("people/#{options[:person_id]}/documents", options.merge(creds))
20
+ end
21
+
22
+ def person_locations(options={})
23
+ response = get("people/#{options[:person_id]}/locations", options.merge(creds))
24
+ end
25
+
26
+ def person_companies(options={})
27
+ response = get("people/#{options[:person_id]}/documents", options.merge(creds))
28
+ end
29
+
30
+ def person_schools(options={})
31
+ response = get("people/#{options[:person_id]}/documents", options.merge(creds))
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,17 @@
1
+ module Knodes
2
+ class Client
3
+ module Schools
4
+ def school(options={})
5
+ response = get("schools/#{options[:school_id]}", options.merge(creds))
6
+ end
7
+
8
+ def schools_search(options={})
9
+ response = get("schools/search", options.merge(creds))
10
+ end
11
+
12
+ def school_people(options={})
13
+ response = get("schools/#{options[:school_id]}/people", options.merge(creds))
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,41 @@
1
+ module Knodes
2
+ class Client
3
+ module Users
4
+ def user(options={})
5
+ response = get("users/#{options[:user_id]}", options.merge(creds))
6
+ end
7
+
8
+ def user_connect(options={})
9
+ response = post("users/connect", options.merge(creds))
10
+ end
11
+
12
+ def user_disconnect(options={})
13
+ response = post("users/disconnect", options.merge(creds))
14
+ end
15
+
16
+ def user_update(options={})
17
+ response = post("users/#{options[:user_id]}", options.merge(creds))
18
+ end
19
+
20
+ def user_notify_active(options={})
21
+ response = post("users/notify_active", options.merge(creds))
22
+ end
23
+
24
+ def user_notify_inactive(options={})
25
+ #do a raw request/response (don't parse), as this method only returns an http status
26
+ response = post("users/notify_inactive", options.merge(creds), true)
27
+ status = response.env[:status]
28
+ end
29
+
30
+ def user_ready(options={})
31
+ response = get("users/#{options[:user_id]}/ready", options.merge(creds), true)
32
+ body = response.env[:body]
33
+ end
34
+
35
+ def user_do_index(options={})
36
+ response = post("users/#{options[:user_id]}/do_index", options.merge(creds), true)
37
+ status = response.env[:status]
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,67 @@
1
+ module Knodes
2
+ module Configuration
3
+ VALID_OPTIONS_KEYS = [
4
+ :customer_id,
5
+ :customer_secret,
6
+ :endpoint,
7
+ :adapter,
8
+ :format,
9
+ :proxy,
10
+ :user_agent
11
+ ].freeze
12
+
13
+ attr_accessor *VALID_OPTIONS_KEYS
14
+
15
+ ##DEFAULT CONSTANTS##
16
+
17
+ # The adapter that will be used to connect if none is set
18
+ # The default faraday adapter is Net::HTTP.
19
+ DEFAULT_ADAPTER = Faraday.default_adapter
20
+
21
+ # By default, don't set a customer ID
22
+ DEFAULT_CUSTOMER_ID = nil
23
+
24
+ # By default, don't set a customer secret
25
+ DEFAULT_CUSTOMER_SECRET = nil
26
+
27
+ # The endpoint that will be used to connect if none is set
28
+ DEFAULT_ENDPOINT = 'https://api.knod.es/'
29
+
30
+ # By default, don't use a proxy server
31
+ DEFAULT_PROXY = nil
32
+
33
+ # The response format appended to the path and sent in the 'Accept' header if none is set
34
+ # JSON is the only available format at this time
35
+ DEFAULT_FORMAT = :json
36
+
37
+ # The user agent that will be sent to the API endpoint if none is set
38
+ DEFAULT_USER_AGENT = 'KnodesRubyClient/1.0'
39
+
40
+ #allow config values to be set in a block
41
+ def configure
42
+ yield self
43
+ end
44
+
45
+ #return hash of options
46
+ def options
47
+ VALID_OPTIONS_KEYS.inject({}) do |option, key|
48
+ option.merge!(key => send(key))
49
+ end
50
+ end
51
+
52
+ # When this module is extended, set all configuration options to their default values
53
+ def self.extended(base)
54
+ base.reset
55
+ end
56
+
57
+ def reset
58
+ self.adapter = DEFAULT_ADAPTER
59
+ self.customer_id = DEFAULT_CUSTOMER_ID
60
+ self.customer_secret = DEFAULT_CUSTOMER_SECRET
61
+ self.endpoint = DEFAULT_ENDPOINT
62
+ self.format = DEFAULT_FORMAT
63
+ self.proxy = DEFAULT_PROXY
64
+ self.user_agent = DEFAULT_USER_AGENT
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,23 @@
1
+ #require the shiny custom middleware
2
+ Dir[File.expand_path('../../faraday/*.rb', __FILE__)].each{|f| require f}
3
+
4
+ module Knodes
5
+ module Connection
6
+ def connection(raw=false)
7
+ options = {
8
+ :headers => {'Accept' => "application/#{format}; charset=utf-8", 'User-Agent' => user_agent},
9
+ :proxy => proxy,
10
+ :ssl => {:verify => false},
11
+ :url => endpoint,
12
+ }
13
+
14
+ Faraday::Connection.new(options) do |connection|
15
+ connection.request :url_encoded
16
+ connection.response :mashify unless raw
17
+ connection.response :json, content_type: 'application/json' unless raw
18
+ connection.use FaradayMiddleware::KnodesErrors
19
+ connection.adapter(adapter)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ module Knodes
2
+ # Custom error class for rescuing from all Knodes errors
3
+ class Error < StandardError; end
4
+
5
+ # Raised when Knodes returns the HTTP status code 400
6
+ class BadRequest < Error; end
7
+
8
+ # Raised when Knodes returns the HTTP status code 404
9
+ class NotFound < Error; end
10
+ end
@@ -0,0 +1,46 @@
1
+ module Knodes
2
+ module Request
3
+ # Perform an HTTP GET request
4
+ def get(path, options={}, raw=false, unformatted=false, debug=false)
5
+ request(:get, path, options, raw, unformatted, debug)
6
+ end
7
+
8
+ # Perform an HTTP POST request
9
+ def post(path, options={}, raw=false, unformatted=false, debug=false)
10
+ request(:post, path, options, raw, unformatted, debug)
11
+ end
12
+
13
+ # Perform an HTTP PUT request
14
+ def put(path, options={}, raw=false, unformatted=false, debug=false)
15
+ request(:put, path, options, raw, unformatted, debug)
16
+ end
17
+
18
+ # Perform an HTTP DELETE request
19
+ def delete(path, options={}, raw=false, unformatted=false, debug=false)
20
+ request(:delete, path, options, raw, unformatted, debug)
21
+ end
22
+
23
+ private
24
+
25
+ # Perform an HTTP request
26
+ def request(method, path, options, raw=false, unformatted=false, debug=false)
27
+ response = connection(raw).send(method) do |request|
28
+ path = formatted_path(path) unless unformatted
29
+ case method
30
+ when :get, :delete
31
+ request.url(path, options)
32
+ when :post, :put
33
+ request.path = path
34
+ request.body = options unless options.empty?
35
+ end
36
+
37
+ puts response.inspect if debug
38
+ end
39
+ raw ? response : response.body
40
+ end
41
+
42
+ def formatted_path(path)
43
+ [path, format].compact.join('.')
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Knodes
2
+ VERSION = "0.3"
3
+ end
File without changes
@@ -0,0 +1,378 @@
1
+ require 'spec_helper'
2
+
3
+ describe Knodes::Client do
4
+ before do
5
+ Knodes.configure do |config|
6
+ config.customer_id = ENV['CUSTOMER_ID']
7
+ config.customer_secret = ENV['CUSTOMER_SECRET']
8
+ end
9
+ end
10
+
11
+ context "Client" do
12
+ it "should make a client" do
13
+ c = Knodes.client
14
+ c.should be_an_instance_of (Knodes::Client)
15
+ end
16
+
17
+ it "should allow me to set configuration in a block " do
18
+ Knodes.configure do |config|
19
+ config.customer_id = "foo"
20
+ config.customer_secret = "bar"
21
+ end
22
+ #puts Knodes.customer_id
23
+ Knodes.customer_id.should == "foo"
24
+ end
25
+
26
+ it "should instantiate using default configuration values" do
27
+ c = Knodes::Client.new
28
+ c.endpoint.should == "https://api.knod.es/"
29
+ end
30
+
31
+ it "should instantiate using specified configuration values" do
32
+ c = Knodes.client(:customer_id=>"foo", :customer_secret=>"bar")
33
+ c.customer_id.should == "foo"
34
+ c.customer_secret.should == "bar"
35
+ end
36
+
37
+ end
38
+
39
+ context "Customers" do
40
+ before do
41
+ @test_app_id = ENV['TEST_APP_ID']
42
+ @test_app_secret = ENV['TEST_APP_SECRET']
43
+ #Knodes = Knodes.client(:customer_id=>@test_customer_id, :customer_secret=>@test_customer_secret)
44
+ end
45
+
46
+ it "should connect to the customer endpoint" do
47
+ response = Knodes.customer
48
+ #puts response
49
+ #puts "\nCustomer App Name: #{response.name}\n"
50
+ response.should have_key(:name)
51
+ end
52
+
53
+ it "should disconnect a customer network app" do
54
+ #response = Knodes.customer_disconnect(:network=>"facebook")
55
+ #puts response.network_apps
56
+ pending("don't want to run this every time")
57
+ #response.network_apps.should_not have_key(:facebook)
58
+ end
59
+
60
+ it "should connect a customer network app" do
61
+ #response = Knodes.customer_connect(:network=>"facebook", :id=>@test_app_id, :secret=>@test_app_secret)
62
+ #puts response.network_apps
63
+ pending("don't want to run this every time")
64
+ #response.network_apps.should have_key(:facebook)
65
+ end
66
+ end
67
+
68
+ context "Users" do
69
+ before do
70
+ @test_user_id = ENV['TEST_USER_ID']
71
+ @test_network_id = ENV['TEST_NETWORK_ID']
72
+ @test_network_token = ENV['TEST_NETWORK_TOKEN']
73
+ #@c = Knodes.client(:customer_id=>@test_customer_id, :customer_secret=>@test_customer_secret)
74
+ end
75
+
76
+ it "should return a user" do
77
+ response = Knodes.user(:user_id=>@test_user_id)
78
+ #puts "\nUser Name: #{response.name}"
79
+ #puts response.inspect
80
+ response.should have_key(:name)
81
+ end
82
+
83
+ it "should fail gracefully with an incorrect id" do
84
+ lambda {
85
+ Knodes.user(:user_id=>"yo_i_got_a_fake_id")
86
+ }.should raise_error(Knodes::NotFound, "invalid action")
87
+ end
88
+
89
+ it "should disconnect a user's network account" do
90
+ #response = Knodes.user_disconnect(:user_id=>@test_user_id, :network=>"facebook", :network_id=>@test_network_id)
91
+ #puts "User networks: #{response.networks}"
92
+ #pending("don't want to run this every time")
93
+ response.networks.should_not have_key(:facebook)
94
+ end
95
+
96
+ it "should connect a user's network account" do
97
+ response = Knodes.user_connect(:network=>"facebook", :network_id=>@test_network_id, :token=>@test_network_token)
98
+ puts response.inspect
99
+ #pending("don't want to run this every time")
100
+ response.networks.should have_key(:facebook)
101
+ end
102
+
103
+ it "should notify_inactive" do
104
+ response = Knodes.user_notify_inactive(:user_id=>@test_user_id)
105
+ #puts "\nNotify inactive status: #{response}"
106
+ response.should == 200
107
+ end
108
+
109
+ it "should notify_active" do
110
+ response = Knodes.user_notify_active(:user_id=>@test_user_id)
111
+ #puts "\nNotify active user name: #{response.name}"
112
+ #puts "\nNotify active ready status: #{response.ready}"
113
+ response.should have_key(:name)
114
+ response.ready.should == "ok" || response.ready.should == "indexing"
115
+ end
116
+
117
+ it "should return ready status" do
118
+ response = Knodes.user_ready(:user_id=>@test_user_id)
119
+ #puts "\nReady status: #{response}"
120
+ response.should == "ok" || response.ready.should == "indexing"
121
+ end
122
+
123
+ it "should initiate a user index" do
124
+ #response = Knodes.user_do_index(:user_id=>@test_user_id)
125
+ #puts "\nUser index status: #{response}"
126
+ #response.should == 200
127
+ pending ("dont want to hit knodes too hard")
128
+ end
129
+
130
+ it "should update a users email address" do
131
+ response = Knodes.user_update(:user_id=>@test_user_id, :email=>"test@example.com")
132
+ response.email.should == "test@example.com"
133
+ end
134
+ end
135
+
136
+ context "People" do
137
+ before do
138
+ @test_user_id = ENV['TEST_USER_ID']
139
+ @test_person_id = ENV['TEST_PERSON_ID']
140
+ #@c = Knodes.client(:customer_id=>@test_customer_id, :customer_secret=>@test_customer_secret)
141
+ end
142
+
143
+ it "should return a person" do
144
+ response = Knodes.person(:user_id=>@test_user_id, :person_id=>@test_person_id)
145
+ #puts response.inspect
146
+ response.should have_key(:name)
147
+ end
148
+
149
+ it "should search for people" do
150
+ response = Knodes.people_search(:user_id=>@test_user_id, :person_id=>"self", :q=>"Person")
151
+ #puts response.results
152
+ response.results.should_not be_empty
153
+ end
154
+
155
+ it "should search for people and fail gracefully" do
156
+ response = Knodes.people_search(:user_id=>@test_user_id, :q=>"Unknown")
157
+ #puts response
158
+ response.should have_key(:total)
159
+ end
160
+
161
+ it "should find people associated with self" do
162
+ response = Knodes.person_people(:user_id=>@test_user_id, :person_id=>"self")
163
+ #puts response.inspect
164
+ response.results.should_not be_empty
165
+ end
166
+
167
+ it "should find people associated with a person" do
168
+ response = Knodes.person_people(:user_id=>@test_user_id, :person_id=>@test_person_id)
169
+ #puts response.inspect
170
+ #response.results.should_not be_empty
171
+ pending "further testing"
172
+ end
173
+
174
+ it "should find documents associated with a person" do
175
+ response = Knodes.person_documents(:user_id=>@test_user_id, :person_id=>@test_person_id, :q=>"")
176
+ response.should have_key(:total)
177
+ end
178
+
179
+ it "should find locations associated with a person" do
180
+ response = Knodes.person_locations(:user_id=>@test_user_id, :person_id=>@test_person_id, :q=>"")
181
+ response.should have_key(:total)
182
+ end
183
+
184
+ it "should find companies associated with a person" do
185
+ response = Knodes.person_companies(:user_id=>@test_user_id, :person_id=>@test_person_id, :q=>"")
186
+ response.should have_key(:total)
187
+ end
188
+
189
+ it "should find schools associated with a person" do
190
+ response = Knodes.person_schools(:user_id=>@test_user_id, :person_id=>@test_person_id, :q=>"")
191
+ response.should have_key(:total)
192
+ end
193
+ end
194
+
195
+ context "Documents" do
196
+ before do
197
+ @test_user_id = ENV['TEST_USER_ID']
198
+ @test_person_id = ENV['TEST_PERSON_ID']
199
+ @test_doc_id = ENV['TEST_DOC_ID']
200
+ #@c = Knodes.client(:customer_id=>@test_customer_id, :customer_secret=>@test_customer_secret)
201
+ end
202
+
203
+ it "should return a document" do
204
+ response = Knodes.document(:user_id=>@test_user_id, :doc_id=>@test_doc_id)
205
+ #puts response.inspect
206
+ response.should have_key(:id)
207
+ end
208
+
209
+ it "should search for documents" do
210
+ response = Knodes.documents_search(:user_id=>@test_user_id, :q=>"profile")
211
+ #puts response.results
212
+ response.total.should > 0
213
+ end
214
+
215
+ it "should search for documents and fail gracefully" do
216
+ response = Knodes.documents_search(:user_id=>@test_user_id, :type=> "document", :q=>"Unknown")
217
+ #puts response
218
+ response.should have_key(:total)
219
+ end
220
+
221
+ it "should find documents associated with self" do
222
+ response = Knodes.documents_search(:user_id=>@test_user_id, :q=>"")
223
+ #puts response.inspect
224
+ response.total.should > 0
225
+ end
226
+
227
+ it "should find people associated with a document" do
228
+ response = Knodes.document_people(:user_id=>@test_user_id, :doc_id=>@test_doc_id)
229
+ #puts response.inspect
230
+ pending "finding a document with associated people"
231
+ response.total.should > 0
232
+ end
233
+
234
+ it "should find locations associated with a document" do
235
+ response = Knodes.document_locations(:user_id=>@test_user_id, :doc_id=>@test_doc_id)
236
+ #puts response.inspect
237
+ pending "finding a document with a location"
238
+ response.total.should > 0
239
+ end
240
+ end
241
+
242
+ context "Locations" do
243
+ before do
244
+ @test_user_id = ENV['TEST_USER_ID']
245
+ @test_person_id = ENV['TEST_PERSON_ID']
246
+ @test_location_id = ENV['TEST_LOCATION_ID']
247
+ #@c = Knodes.client(:customer_id=>@test_customer_id, :customer_secret=>@test_customer_secret)
248
+ end
249
+
250
+ it "should return a location" do
251
+ response = Knodes.location(:user_id=>@test_user_id, :location_id=>@test_location_id)
252
+ #puts response.inspect
253
+ response.should have_key(:id)
254
+ end
255
+
256
+ it "should search for locations" do
257
+ response = Knodes.locations_search(:user_id=>@test_user_id, :q=>"New York")
258
+ #puts response.results
259
+ response.total.should > 0
260
+ end
261
+
262
+ it "should search for locations and fail gracefully" do
263
+ response = Knodes.locations_search(:user_id=>@test_user_id, :type=> "location", :q=>"Unknown")
264
+ #puts response
265
+ response.should have_key(:total)
266
+ end
267
+
268
+ it "should find locations associated with self" do
269
+ response = Knodes.locations_search(:user_id=>@test_user_id, :q=>"")
270
+ #puts response.inspect
271
+ response.total.should > 0
272
+ end
273
+
274
+ it "should find people associated with a location" do
275
+ response = Knodes.location_people(:user_id=>@test_user_id, :location_id=>@test_location_id)
276
+ #puts response.inspect
277
+ #response.total.should > 0
278
+ pending "finding a location with people"
279
+ end
280
+
281
+ it "should find documents associated with a location" do
282
+ response = Knodes.location_documents(:user_id=>@test_user_id, :location_id=>@test_location_id)
283
+ #puts response.inspect
284
+ #response.total.should > 0
285
+ pending "finding a location with documents"
286
+ end
287
+ end
288
+
289
+ context "Companies" do
290
+ before do
291
+ @test_user_id = ENV['TEST_USER_ID']
292
+ @test_person_id = ENV['TEST_PERSON_ID']
293
+ @test_company_id = ENV['TEST_COMPANY_ID']
294
+ #@c = Knodes.client(:customer_id=>@test_customer_id, :customer_secret=>@test_customer_secret)
295
+ end
296
+
297
+ it "should return a company" do
298
+ pending "finding a company"
299
+ response = Knodes.company(:user_id=>@test_user_id, :company_id=>@test_company_id)
300
+ #puts response.inspect
301
+ #response.should have_key(:id)
302
+
303
+ end
304
+
305
+ it "should search for companies" do
306
+ pending "finding a company"
307
+ response = Knodes.companies_search(:user_id=>@test_user_id, :q=>"New York")
308
+ #puts response.results
309
+ #response.total.should > 0
310
+ end
311
+
312
+ it "should search for companies and fail gracefully" do
313
+ response = Knodes.companies_search(:user_id=>@test_user_id, :type=> "company", :q=>"Unknown")
314
+ #puts response
315
+ response.should have_key(:total)
316
+ end
317
+
318
+ it "should find companies associated with self" do
319
+ pending "finding a company"
320
+ response = Knodes.companies_search(:user_id=>@test_user_id, :q=>"")
321
+ #puts response.inspect
322
+ #response.total.should > 0
323
+ end
324
+
325
+ it "should find people associated with a company" do
326
+ pending "finding a company"
327
+ response = Knodes.company_people(:user_id=>@test_user_id, :company_id=>@test_company_id)
328
+ #puts response.inspect
329
+ #response.total.should > 0
330
+ end
331
+ end
332
+
333
+ context "Schools" do
334
+ before do
335
+ @test_user_id = ENV['TEST_USER_ID'] #
336
+ @test_person_id = ENV['TEST_PERSON_ID']
337
+ @test_school_id = ENV['TEST_SCHOOL_ID']
338
+ #@c = Knodes.client(:customer_id=>@test_customer_id, :customer_secret=>@test_customer_secret)
339
+ end
340
+
341
+ it "should return a school" do
342
+ response = Knodes.school(:user_id=>@test_user_id, :school_id=>@test_school_id)
343
+ # puts response.inspect
344
+ response.should have_key(:id)
345
+
346
+ end
347
+
348
+ it "should search for schools" do
349
+ response = Knodes.schools_search(:user_id=>@test_user_id, :q=>"Rensselaer")
350
+ #puts response.results
351
+ response.total.should > 0
352
+ end
353
+
354
+ it "should search for schools and fail gracefully" do
355
+ response = Knodes.schools_search(:user_id=>@test_user_id, :type=> "school", :q=>"Unknown")
356
+ #puts response
357
+ response.should have_key(:total)
358
+ end
359
+
360
+ it "should find schools associated with self" do
361
+ response = Knodes.schools_search(:user_id=>@test_user_id, :q=>"")
362
+ #puts response.inspect
363
+ response.total.should > 0
364
+ end
365
+
366
+ it "should find people associated with a school" do
367
+ response = Knodes.school_people(:user_id=>@test_user_id, :school_id=>@test_school_id)
368
+ #puts response.inspect
369
+ response.total.should > 0
370
+ end
371
+ end
372
+
373
+ end
374
+
375
+
376
+
377
+
378
+
@@ -0,0 +1,8 @@
1
+ require 'rspec'
2
+ require 'rack/test'
3
+ require 'dotenv'
4
+
5
+ Dotenv.load
6
+ Dir[File.expand_path('../../lib/*.rb', __FILE__)].each{|f| require f}
7
+ ENV['RACK_ENV'] = 'test'
8
+ set :environment, :test
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knodes
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.3'
5
+ platform: ruby
6
+ authors:
7
+ - Matt Anderson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 2.5.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 2.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: See API documentation at http://developer.knod.es/
56
+ email:
57
+ - matthewrossanderson@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .env
63
+ - .gitignore
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - Guardfile
67
+ - README.md
68
+ - knodes.gemspec
69
+ - lib/.DS_Store
70
+ - lib/faraday/knodes_errors.rb
71
+ - lib/knodes.rb
72
+ - lib/knodes/client.rb
73
+ - lib/knodes/client/companies.rb
74
+ - lib/knodes/client/customers.rb
75
+ - lib/knodes/client/documents.rb
76
+ - lib/knodes/client/locations.rb
77
+ - lib/knodes/client/people.rb
78
+ - lib/knodes/client/schools.rb
79
+ - lib/knodes/client/users.rb
80
+ - lib/knodes/configuration.rb
81
+ - lib/knodes/connection.rb
82
+ - lib/knodes/error.rb
83
+ - lib/knodes/request.rb
84
+ - lib/version.rb
85
+ - spec/lib/.github
86
+ - spec/lib/knodes_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: http://developer.knod.es/
89
+ licenses:
90
+ - Apache 2.0
91
+ metadata: {}
92
+ post_install_message: ! '********************************************************************************
93
+
94
+
95
+ Thanks for installing the Knodes client library!
96
+
97
+
98
+ See API documentation at http://developer.knod.es/
99
+
100
+
101
+ There''s always money in the banana stand.
102
+
103
+
104
+ ********************************************************************************
105
+
106
+ '
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project: knodes
122
+ rubygems_version: 2.0.3
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: A ruby client library for the Knodes API
126
+ test_files:
127
+ - spec/lib/.github
128
+ - spec/lib/knodes_spec.rb
129
+ - spec/spec_helper.rb