open_calais 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # OpenCalais
2
2
 
3
- Ruby gem to access the OpenCalaid API, using the new-ish REST API, and JSON responses.
4
- It uses Faraday to abstract HTTP library (defaults to use excon because ot is excellent), and multi_json to abstract JSON parsing.
3
+ Ruby gem to access the [OpenCalais API](http://www.opencalais.com/documentation/calais-web-service-api/api-invocation/rest), using the new-ish REST API, and JSON responses.
4
+ It uses [Faraday](https://github.com/lostisland/faraday) to abstract HTTP library (defaults to use excon because it is excellent), and multi_json to abstract JSON parsing.
5
5
 
6
- It returns a parsed version of the response, but the response contains the raw response (converted from json to hashes/arrays/string/etc).
6
+ It returns a parsed version of the response, but the response also contains the raw response (converted from json to hashes/arrays/string/etc).
7
7
 
8
8
  ## Installation
9
9
 
@@ -21,28 +21,29 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
- OpenCalais has one main method, 'enrich', and so does the gem:
24
+ OpenCalais has one main method, `enrich`, and so does the gem:
25
25
 
26
- require 'open_calais'
26
+ ```ruby
27
+ require 'open_calais'
27
28
 
28
- # you can configure for all calls
29
- OpenCalais.configure do |c|
30
- c.api_key = "this is a test key"
31
- end
29
+ # you can configure for all calls
30
+ OpenCalais.configure do |c|
31
+ c.api_key = "this is a test key"
32
+ end
32
33
 
33
- # or you can configure for a single call
34
- open_calais = OpenCalais::Client.new(:api_key=>'an api key')
34
+ # or you can configure for a single call
35
+ open_calais = OpenCalais::Client.new(:api_key=>'an api key')
35
36
 
36
- # it returns a OpenCalais::Response instance
37
- response = open_calais.enrich('Ruby on Rails is a fantastic web framework. It uses MVC, and the Ruby programming language invented by Matz in Japan.')
37
+ # it returns a OpenCalais::Response instance
38
+ response = open_calais.enrich('Ruby on Rails is a fantastic web framework. It uses MVC, and the Ruby programming language invented by Matz in Japan.')
38
39
 
39
- # which has the 'raw' response
40
- response.raw
41
-
42
- # and has been parsed a bit to get :language, :topics, :tags, :entities, :relations, :locations
43
- # as lists of hashes
44
- response.tags.each{|t| puts t[:name] }
40
+ # which has the 'raw' response
41
+ response.raw
45
42
 
43
+ # and has been parsed a bit to get :language, :topics, :tags, :entities, :relations, :locations
44
+ # as lists of hashes
45
+ response.tags.each{|t| puts t[:name] }
46
+ ```
46
47
 
47
48
  ## Contributing
48
49
 
@@ -1,3 +1,5 @@
1
+ # -*- encoding: utf-8 -*-
2
+
1
3
  require 'open_calais/configuration'
2
4
  require 'open_calais/connection'
3
5
  require 'open_calais/response'
@@ -35,12 +37,10 @@ module OpenCalais
35
37
 
36
38
  def enrich(text, opts={})
37
39
  raise 'Specify a value for the text' unless (text && text.length > 0)
40
+ options = current_options.merge(opts)
38
41
 
39
- response = connection.post do |request|
42
+ response = connection(options).post do |request|
40
43
  request.body = text
41
- OpenCalais::HEADERS.each do |k,v|
42
- request.headers[v] = opts[k] if opts.key?(k)
43
- end
44
44
  end
45
45
  OpenCalais::Response.new(response)
46
46
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # -*- encoding: utf-8 -*-
2
2
 
3
3
  module OpenCalais
4
4
  module Configuration
@@ -1,3 +1,5 @@
1
+ # -*- encoding: utf-8 -*-
2
+
1
3
  require 'faraday_middleware'
2
4
 
3
5
  module OpenCalais
@@ -11,7 +13,7 @@ module OpenCalais
11
13
  :ssl
12
14
  ].freeze
13
15
 
14
- def add_default_options(opts={})
16
+ def merge_default_options(opts={})
15
17
  headers = opts.delete(:headers) || {}
16
18
  options = {
17
19
  :headers => {
@@ -32,13 +34,14 @@ module OpenCalais
32
34
  :url => endpoint
33
35
  }.merge(opts)
34
36
  options[:headers] = options[:headers].merge(headers)
37
+ OpenCalais::HEADERS.each{|k,v| options[:headers][v] = options.delete(k) if options.key?(k)}
35
38
  options
36
39
  end
37
40
 
38
41
  def connection(options={})
39
- opts = add_default_options(options)
42
+ opts = merge_default_options(options)
40
43
  Faraday::Connection.new(opts) do |connection|
41
- connection.request :url_encoded
44
+ connection.request :url_encoded
42
45
  connection.response :mashify
43
46
  connection.response :logger if ENV['DEBUG']
44
47
 
@@ -49,7 +52,6 @@ module OpenCalais
49
52
  end
50
53
 
51
54
  connection.adapter(adapter)
52
-
53
55
  end
54
56
 
55
57
  end
@@ -1,3 +1,5 @@
1
+ # -*- encoding: utf-8 -*-
2
+
1
3
  module OpenCalais
2
4
  class Response
3
5
  attr_accessor :raw, :language, :topics, :tags, :entities, :relations, :locations
@@ -1,3 +1,5 @@
1
+ # -*- encoding: utf-8 -*-
2
+
1
3
  module OpenCalais
2
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
3
5
  end
@@ -1,3 +1,5 @@
1
+ # -*- encoding: utf-8 -*-
2
+
1
3
  require 'minitest/spec'
2
4
  require 'minitest/autorun'
3
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_calais
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-08 00:00:00.000000000 Z
12
+ date: 2013-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -187,12 +187,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
187
  - - ! '>='
188
188
  - !ruby/object:Gem::Version
189
189
  version: '0'
190
+ segments:
191
+ - 0
192
+ hash: -4380033744204018911
190
193
  required_rubygems_version: !ruby/object:Gem::Requirement
191
194
  none: false
192
195
  requirements:
193
196
  - - ! '>='
194
197
  - !ruby/object:Gem::Version
195
198
  version: '0'
199
+ segments:
200
+ - 0
201
+ hash: -4380033744204018911
196
202
  requirements: []
197
203
  rubyforge_project:
198
204
  rubygems_version: 1.8.23
@@ -204,4 +210,3 @@ test_files:
204
210
  - test/configuration_test.rb
205
211
  - test/open_calais_test.rb
206
212
  - test/test_helper.rb
207
- has_rdoc: