biffbot 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzkzZWQzN2MyODFkMmNiZjU4MTU5NWM5ZTk3ZTI4MWM2ODBkMDU5OA==
4
+ YmIwNzhmMTgwNWI3YTExMDE4OGJjMDExN2M1NDFlMjU0MGJhYTI4NQ==
5
5
  data.tar.gz: !binary |-
6
- Yzg4ZTdhMjI0MzM2NmMxMTVhMjA2MTIxOTUzZTMwYTdkOWRmZTQ0NA==
6
+ Zjg4NjU1NmI3OTI1ZTRkZWQwOWNlOTVkZGZiYjQxZDgyNzMyNzVlNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDNmMWQxZWY5YmJhMmQ0YzRiMjZlMTNkMDY1Yjg1OTJkNmYwYzQ4Yzc1MGJl
10
- NzYwYjc4MzU4NWFmNjNhOWQ4MDIzNjliZjJkZTJmM2U2Y2Y5ZDI0OThiYTkw
11
- MTA2ZjIxNTAxYjcwYzg2Yzc2ZWM4NWQ0ZjQ2ZWFmM2FlYWVhYzE=
9
+ ZGI0ZTMzNjRlY2QxOGZmZDFjNjlkMzhhNmQwNDVhY2M2ZjQ2YjIxMGI0OTg5
10
+ N2ZlNWExNDMyNzQ0MjZmZDFhNDdhZjNmNzVhOWU0NTkzZDc3Njk4YTVjMzRk
11
+ OWU1MzA3MjNhNDdhOGU4NTBkZmQ5YjVlM2M2MjgyZTY1M2ZkMGI=
12
12
  data.tar.gz: !binary |-
13
- Nzg5ZjY0MDFmYmMyYzlhNjhlY2FjM2U0ZmQ2NWFjNTNlZjg1ODczNjEzOTkw
14
- MGVkMzE5ODNkYzM4MTFhM2Q3OTNhNGY1YzMzMDI5MGQxYzFmNjU5MzY1YTJl
15
- YmE2YTk4ODIxNjg2YjNhYWMzODg4YzBmMjc0MWZkZGYyYTU0NzU=
13
+ OGIwY2QwNjAzMGJjNDdhNzcwNzNhZGYwZjBjZGJiMzczMjk1NDg4OTM3OTM0
14
+ YzNlY2RhMzc2MjJiOWI0YTllMjYzMDM0OWIyMDlkMjlmYjRiMzE1YjBiMWQ0
15
+ MmE4YTZlODdhZGQ0NDBjM2VjODZiNzkyMzE4NzljZjlkNGU2ZWI=
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- # Biffbot
2
- [![Build Status](https://travis-ci.org/tevren/biffbot.svg?branch=master)](https://travis-ci.org/tevren/biffbot) [![Gem Version](https://badge.fury.io/rb/biffbot.svg)](http://badge.fury.io/rb/biffbot) [![Code Climate](https://codeclimate.com/github/tevren/biffbot/badges/gpa.svg)](https://codeclimate.com/github/tevren/biffbot)
1
+ # Biffbot [![Build Status](https://travis-ci.org/tevren/biffbot.svg?branch=master)](https://travis-ci.org/tevren/biffbot) [![Gem Version](https://badge.fury.io/rb/biffbot.svg)](http://badge.fury.io/rb/biffbot) [![Code Climate](https://codeclimate.com/github/tevren/biffbot/badges/gpa.svg)](https://codeclimate.com/github/tevren/biffbot) [![Test Coverage](https://codeclimate.com/github/tevren/biffbot/badges/coverage.svg)](https://codeclimate.com/github/tevren/biffbot)
3
2
 
4
3
  Ruby gem to connect to diffbot's APIs
5
4
 
@@ -19,23 +18,14 @@ Or install it yourself as:
19
18
 
20
19
  ## Usage
21
20
 
22
- Usage example:
23
- OLD DEPCRECATED METHOD:
21
+ ### Usage example:
24
22
 
25
23
  require 'biffbot'
26
- token = YOUR_DEVELOPER_TOKEN
27
- biff = Biffbot::Base.new(token)
28
- article = biff.parse("the url you want to parse",options)
24
+ Biffbot.token = YOUR_DEVELOPER_TOKEN
25
+ analyze = Biffbot::Analyze.new(url, {:type => 'article'})
26
+ article = Biffbot::Article.new(url,some_hash_of_options)
29
27
 
30
- NEW METHOD:
31
-
32
- require 'biffbot'
33
- token = YOUR_DEVELOPER_TOKEN
34
- analyze = Biffbot::Analyze.new(token, url, {:type => 'article'})
35
- article = Biffbot::Article.new(@token,url,some_hash_of_options)
36
-
37
-
38
- The available classes are:
28
+ #### Available classes:
39
29
  * Biffbot::Analyze
40
30
  * Biffbot::Article
41
31
  * Biffbot::Image
@@ -16,11 +16,13 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(/^bin\//) { |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(/^(test|spec|features)\//)
18
18
  gem.require_paths = ['lib']
19
- gem.add_dependency('httparty')
19
+ gem.add_dependency('httparty', '~> 0.13')
20
20
  gem.add_dependency('json', '~> 1.8')
21
21
  gem.add_dependency('hashie', '~> 3.3')
22
22
  gem.add_development_dependency('rspec')
23
23
  gem.add_development_dependency('rake')
24
24
  gem.add_development_dependency('rubocop')
25
25
  gem.add_development_dependency('dotenv')
26
+ gem.add_development_dependency('yard')
27
+ gem.add_development_dependency('codeclimate-test-reporter')
26
28
  end
@@ -8,9 +8,15 @@ require 'biffbot/image'
8
8
  require 'biffbot/product'
9
9
 
10
10
  module Biffbot
11
+ def self.configure
12
+ yield self
13
+ self
14
+ end
15
+
11
16
  def self.reset!
12
17
  @token = nil
13
18
  end
14
19
  class << self
20
+ attr_accessor :token
15
21
  end
16
22
  end
@@ -1,9 +1,16 @@
1
1
  require 'biffbot/base'
2
2
  module Biffbot
3
3
  class Analyze < Base
4
- def initialize token, url, options = {}
5
- @token = token
6
- parse(@token, 'analyze', url, options)
4
+ # a new instance of Biffbot::Analyze
5
+ #
6
+ # @param url [String] The url to analyze
7
+ # @param options [Hash] An hash of options
8
+ # @param token [String] Override Biffbot.token with another token
9
+ # @return [Hash]
10
+ # @example
11
+ # Biffbot::Analyze('http://www.nytimes.com', mode: 'article', timeout: 60) => {SOME_HASH}
12
+ def initialize url, options = {}, token = Biffbot.token
13
+ parse(token, 'analyze', url, options)
7
14
  end
8
15
  end
9
16
  end
@@ -1,9 +1,16 @@
1
1
  require 'biffbot/base'
2
2
  module Biffbot
3
3
  class Article < Base
4
- def initialize token, url, options = {}
5
- @token = token
6
- parse(@token, 'article', url, options)
4
+ # a new instance of Biffbot::Article
5
+ #
6
+ # @param url [String] The url of an article to grab
7
+ # @param options [Hash] An hash of options
8
+ # @param token [String] Override Biffbot.token with another token
9
+ # @return [Hash]
10
+ # @example
11
+ # Biffbot::Article('http://www.nytimes.com', timeout: 60) => {SOME_HASH}
12
+ def initialize url, options = {}, token = Biffbot.token
13
+ parse(token, 'article', url, options)
7
14
  end
8
15
  end
9
16
  end
@@ -5,13 +5,26 @@ require 'cgi'
5
5
  module Biffbot
6
6
  class Base < Hash
7
7
  include Hashie::Extensions::Coercion
8
- def parse token = '', type = 'article', url = '', options = {}
8
+ # a new instance of Biffbot::Base
9
+ #
10
+ # @param token [String] Override Biffbot.token with another token
11
+ # @param type [String] pass the class type you're working with
12
+ # @param url [String] The url of the page you're working with
13
+ # @param options [Hash] An hash of options
14
+ # @return [Hash]
15
+ def parse token = Biffbot.token, type = 'article', url = '', options = {}
9
16
  url = parse_options(options, generate_url(CGI.escape(url), token, type, options[:version]))
10
17
  JSON.parse(HTTParty.get(url).body).each_pair do |key, value|
11
18
  self[key] = value
12
19
  end
13
20
  end
14
21
 
22
+ # generate an url consisting of your api key and the endpoint you'd like to use
23
+ #
24
+ # @param url [String] The url to pass to diffbot
25
+ # @param token [String] Diffbot API token
26
+ # @param type [String] API to use
27
+ # @return [String] a formatted url with your api key, endpoint and input url
15
28
  def generate_url url, token, type, version
16
29
  case type
17
30
  when 'analyze'
@@ -25,6 +38,11 @@ module Biffbot
25
38
  url
26
39
  end
27
40
 
41
+ # add the options hash to your input url
42
+ #
43
+ # @param options [Hash] An hash of options
44
+ # @param request [String] The url to append options to
45
+ # @return [String] a formatted url with options merged into the input url
28
46
  def parse_options options = {}, request = ''
29
47
  options.each do |opt, value|
30
48
  case opt
@@ -5,10 +5,20 @@ require 'cgi'
5
5
  module Biffbot
6
6
  class Bulk < Base
7
7
  include Hashie::Extensions::Coercion
8
- def initialize token
8
+ # a new instance of Biffbot::Bulk
9
+ #
10
+ # @param token [String] Override Biffbot.token with another token
11
+ def initialize token = Biffbot.token
9
12
  @token = token
10
13
  end
11
14
 
15
+ # create a bulk job
16
+ #
17
+ # @param name [String] Desired name for bulk job
18
+ # @param api_type [String] Desired API to use for urls
19
+ # @param urls [Array] An array of input urls to pass to bulk job
20
+ # @param options [Hash] An hash of options
21
+ # @return [Hash]
12
22
  def create_job name, api_type, urls = [], options = {}
13
23
  api_url = "http://api.diffbot.com/v2/#{api_type}"
14
24
  api_url = "http://api.diffbot.com/#{options[:version]}/#{api_type}" if options[:version] == 'v2' || options[:version] == 'v3'
@@ -20,6 +30,13 @@ module Biffbot
20
30
  end
21
31
  end
22
32
 
33
+ # generate the POST body required for bulk job creation
34
+ #
35
+ # @param name [String] Desired name for bulk job
36
+ # @param api_url [String] Desired API url to use for urls
37
+ # @param urls [Array] An array of input urls to pass to bulk job
38
+ # @param options [Hash] An hash of options
39
+ # @return [Hash]
23
40
  def generate_post_body name, api_url, urls = [], options = {}
24
41
  post_body = {token: @token, name: name, apiUrl: api_url, urls: urls}
25
42
  options.each do |key, value|
@@ -29,34 +46,28 @@ module Biffbot
29
46
  post_body
30
47
  end
31
48
 
32
- def pause name
33
- endpoint = "http://api.diffbot.com/v3/bulk/?token=#{@token}&name=#{name}&pause=1"
34
- JSON.parse(HTTParty.get(endpoint).body).each_pair do |key, value|
35
- self[key] = value
36
- end
37
- end
38
-
39
- def unpause name
40
- endpoint = "http://api.diffbot.com/v3/bulk/?token=#{@token}&name=#{name}&pause=0"
41
- JSON.parse(HTTParty.get(endpoint).body).each_pair do |key, value|
42
- self[key] = value
43
- end
44
- end
45
-
46
- def restart name
47
- endpoint = "http://api.diffbot.com/v3/bulk/?token=#{@token}&name=#{name}&restart=1"
48
- JSON.parse(HTTParty.get(endpoint).body).each_pair do |key, value|
49
- self[key] = value
50
- end
51
- end
52
-
53
- def delete name
54
- endpoint = "http://api.diffbot.com/v3/bulk/?token=#{@token}&name=#{name}&delete=1"
55
- JSON.parse(HTTParty.get(endpoint).body).each_pair do |key, value|
56
- self[key] = value
49
+ # Using define_method to create methods for each action rather than defining each method seperately.
50
+ %w(pause unpause restart delete view).each do |method_name|
51
+ define_method method_name do |name|
52
+ case method_name
53
+ when 'pause', 'restart', 'delete'
54
+ endpoint = "http://api.diffbot.com/v3/bulk/?token=#{@token}&name=#{name}&#{method_name}=1"
55
+ when 'unpause'
56
+ endpoint = "http://api.diffbot.com/v3/bulk/?token=#{@token}&name=#{name}&#{method_name}=0"
57
+ when 'view'
58
+ endpoint = "http://api.diffbot.com/v3/bulk/?token=#{@token}&name=#{name}"
59
+ end
60
+ JSON.parse(HTTParty.get(endpoint).body).each_pair do |key, value|
61
+ self[key] = value
62
+ end
57
63
  end
58
64
  end
59
65
 
66
+ # retrieve data per given jobName
67
+ #
68
+ # @param jobName [String] Name of bulk job
69
+ # @param _options [Hash] An hash of options
70
+ # @return [Hash]
60
71
  def retrieve_data jobName, _options = {}
61
72
  # TODO: add support for csv
62
73
  endpoint = "http://api.diffbot.com/v3/bulk/download/#{@token}-#{jobName}_data.json"
@@ -64,12 +75,5 @@ module Biffbot
64
75
  self[key] = value
65
76
  end
66
77
  end
67
-
68
- def view name
69
- endpoint = "http://api.diffbot.com/v3/bulk/?token=#{@token}&name=#{name}"
70
- JSON.parse(HTTParty.get(endpoint).body).each_pair do |key, value|
71
- self[key] = value
72
- end
73
- end
74
78
  end
75
79
  end
@@ -1,10 +1,18 @@
1
1
  require 'biffbot/base'
2
2
  module Biffbot
3
3
  class Custom < Base
4
- def initialize token, url, api_name, options = {}
5
- @token = token
4
+ # a new instance of Biffbot::Custom
5
+ #
6
+ # @param url [String] The url to pass to your custom api
7
+ # @param api_name [String] The name of your custom api
8
+ # @param options [Hash] An hash of options
9
+ # @param token [String] Override Biffbot.token with another token
10
+ # @return [Hash]
11
+ # @example
12
+ # Biffbot::Custom('http://www.nytimes.com', 'my_cool_nytimes_api', timeout: 60) => {SOME_HASH}
13
+ def initialize url, api_name, options = {}, token = Biffbot.token
6
14
  options[:api_name] = api_name
7
- parse(@token, 'custom', url, options)
15
+ parse(token, 'custom', url, options)
8
16
  end
9
17
  end
10
18
  end
@@ -1,9 +1,14 @@
1
1
  require 'biffbot/base'
2
2
  module Biffbot
3
3
  class Image < Base
4
- def initialize token, url, options = {}
5
- @token = token
6
- parse(@token, 'image', url, options)
4
+ # a new instance of Biffbot::Image
5
+ #
6
+ # @param url [String] The url of an page with images you want to analyze
7
+ # @param options [Hash] An hash of options
8
+ # @param token [String] Override Biffbot.token with another token
9
+ # @return [Hash]
10
+ def initialize url, options = {}, token = Biffbot.token
11
+ parse(token, 'image', url, options)
7
12
  end
8
13
  end
9
14
  end
@@ -1,9 +1,14 @@
1
1
  require 'biffbot/base'
2
2
  module Biffbot
3
3
  class Product < Base
4
- def initialize token, url, options = {}
5
- @token = token
6
- parse(@token, 'product', url, options)
4
+ # a new instance of Biffbot::Product
5
+ #
6
+ # @param url [String] The url of an page with products you want to analyze
7
+ # @param options [Hash] An hash of options
8
+ # @param token [String] Override Biffbot.token with another token
9
+ # @return [Hash]
10
+ def initialize url, options = {}, token = Biffbot.token
11
+ parse(token, 'product', url, options)
7
12
  end
8
13
  end
9
14
  end
@@ -1,3 +1,3 @@
1
1
  module Biffbot
2
- VERSION = '1.2.3'
2
+ VERSION = '1.2.4'
3
3
  end
@@ -3,9 +3,9 @@ require 'spec_helper'
3
3
  # more tests to come...
4
4
  describe Biffbot::Analyze do
5
5
  before :each do
6
- token = ENV['DIFFBOT_DEV_TOKEN']
7
6
  url = 'http://www.huffingtonpost.ca/2012/10/11/amanda-todd-teen-bullying-suicide-youtube_n_1959668.html'
8
- @article = Biffbot::Analyze.new(token, url, type: 'article')
7
+ Biffbot.token = ENV['DIFFBOT_DEV_TOKEN']
8
+ @article = Biffbot::Analyze.new(url, type: 'article')
9
9
  end
10
10
 
11
11
  describe 'analyze an article' do
@@ -3,9 +3,9 @@ require 'spec_helper'
3
3
  # currently tests v2 article api
4
4
  describe Biffbot::Article do
5
5
  before :each do
6
- token = ENV['DIFFBOT_DEV_TOKEN']
7
6
  url = 'http://www.huffingtonpost.ca/2012/10/11/amanda-todd-teen-bullying-suicide-youtube_n_1959668.html'
8
- @article = Biffbot::Article.new(token, url)
7
+ Biffbot.token = ENV['DIFFBOT_DEV_TOKEN']
8
+ @article = Biffbot::Article.new(url)
9
9
  end
10
10
 
11
11
  describe 'Biffbot::Article.parse' do
@@ -3,9 +3,9 @@ require 'spec_helper'
3
3
  # currently tests v2 image api
4
4
  describe Biffbot::Image do
5
5
  before :each do
6
- token = ENV['DIFFBOT_DEV_TOKEN']
7
6
  url = 'http://www.huffingtonpost.ca/2012/10/11/amanda-todd-teen-bullying-suicide-youtube_n_1959668.html'
8
- @image = Biffbot::Image.new(token, url)
7
+ Biffbot.token = ENV['DIFFBOT_DEV_TOKEN']
8
+ @image = Biffbot::Image.new(url)
9
9
  end
10
10
 
11
11
  describe 'Biffbot::Image.parse' do
@@ -3,9 +3,9 @@ require 'spec_helper'
3
3
  # currently tests v2 product api
4
4
  describe Biffbot::Product do
5
5
  before :each do
6
- token = ENV['DIFFBOT_DEV_TOKEN']
7
6
  url = 'http://www.amazon.com/Google-Chromecast-Streaming-Media-Player/dp/B00DR0PDNE/'
8
- @product = Biffbot::Product.new(token, url)
7
+ Biffbot.token = ENV['DIFFBOT_DEV_TOKEN']
8
+ @product = Biffbot::Product.new(url)
9
9
  end
10
10
 
11
11
  describe 'Biffbot::Product.parse' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biffbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anurag Mohanty
@@ -14,16 +14,16 @@ dependencies:
14
14
  name: httparty
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.13'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '0.13'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,34 @@ dependencies:
108
108
  - - ! '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: codeclimate-test-reporter
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
111
139
  description: Ruby gem to connect to diffbot's article api
112
140
  email:
113
141
  - tevren@gmail.com