Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ deploy:
provider: rubygems
api_key:
secure: QxMWXTQ3/T+0IQZl3pk3hmdoX8FcXTXEhH7Jn7Ub1A1D5faa8VNnfYsWAPjP6+VRgVfKEjAsHNMyZQNTvudpPPC/2kAwwzPvStyS+y7KnRkjZ9acC7sYVVel6cZ2lcl+t8iHY+19NRBFBWpq/P0eCAcR/Ew0XXaLZnig5h/1mQo=
gem: twingly-analytics
gemspec: twingly-analytics-api-ruby.gemspec
gem: twingly-search
gemspec: twingly-search-api-ruby.gemspec
on:
tags: true
rvm: 2.2
repo: twingly/twingly-analytics-api-ruby
repo: twingly/twingly-search-api-ruby
notifications:
email: false
hipchat:
Expand Down
52 changes: 26 additions & 26 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
# Change Log

## [2.0.1](https://github.com/twingly/twingly-analytics-api-ruby/tree/2.0.1) (2015-09-24)
[Full Changelog](https://github.com/twingly/twingly-analytics-api-ruby/compare/2.0.0...2.0.1)
## [2.0.1](https://github.com/twingly/twingly-search-api-ruby/tree/2.0.1) (2015-09-24)
[Full Changelog](https://github.com/twingly/twingly-search-api-ruby/compare/2.0.0...2.0.1)

**Fixed bugs:**

- Crash when pattern is empty string [\#17](https://github.com/twingly/twingly-analytics-api-ruby/issues/17)
- Crash when pattern is empty string [\#17](https://github.com/twingly/twingly-search-api-ruby/issues/17)

**Merged pull requests:**

- Do not allow empty search pattern [\#18](https://github.com/twingly/twingly-analytics-api-ruby/pull/18) ([twingly-mob](https://github.com/twingly-mob))
- Generate Changelog \(with instructions to update it\) [\#16](https://github.com/twingly/twingly-analytics-api-ruby/pull/16) ([jage](https://github.com/jage))
- Do not allow empty search pattern [\#18](https://github.com/twingly/twingly-search-api-ruby/pull/18) ([twingly-mob](https://github.com/twingly-mob))
- Generate Changelog \(with instructions to update it\) [\#16](https://github.com/twingly/twingly-search-api-ruby/pull/16) ([jage](https://github.com/jage))

## [2.0.0](https://github.com/twingly/twingly-analytics-api-ruby/tree/2.0.0) (2015-09-14)
[Full Changelog](https://github.com/twingly/twingly-analytics-api-ruby/compare/1.0.1...2.0.0)
## [2.0.0](https://github.com/twingly/twingly-search-api-ruby/tree/2.0.0) (2015-09-14)
[Full Changelog](https://github.com/twingly/twingly-search-api-ruby/compare/1.0.1...2.0.0)

**Implemented enhancements:**

- Release gem to rubygems.org [\#10](https://github.com/twingly/twingly-analytics-api-ruby/issues/10)
- Release gem to rubygems.org [\#10](https://github.com/twingly/twingly-search-api-ruby/issues/10)

**Merged pull requests:**

- Improve time pagination \(breaking compatibility for Query\#start\_time and Query\#end\_time\) [\#15](https://github.com/twingly/twingly-analytics-api-ruby/pull/15) ([jage](https://github.com/jage))
- Improve time pagination \(breaking compatibility for Query\#start\_time and Query\#end\_time\) [\#15](https://github.com/twingly/twingly-search-api-ruby/pull/15) ([jage](https://github.com/jage))

## [1.0.1](https://github.com/twingly/twingly-analytics-api-ruby/tree/1.0.1) (2015-04-29)
[Full Changelog](https://github.com/twingly/twingly-analytics-api-ruby/compare/1.0.0...1.0.1)
## [1.0.1](https://github.com/twingly/twingly-search-api-ruby/tree/1.0.1) (2015-04-29)
[Full Changelog](https://github.com/twingly/twingly-search-api-ruby/compare/1.0.0...1.0.1)

**Fixed bugs:**

- Support Ruby 2.2 [\#12](https://github.com/twingly/twingly-analytics-api-ruby/issues/12)
- HTTPS broke compatibility with Ruby 1.9.3 [\#8](https://github.com/twingly/twingly-analytics-api-ruby/issues/8)
- Support Ruby 2.2 [\#12](https://github.com/twingly/twingly-search-api-ruby/issues/12)
- HTTPS broke compatibility with Ruby 1.9.3 [\#8](https://github.com/twingly/twingly-search-api-ruby/issues/8)

**Closed issues:**

- Use the rspec-its gem [\#11](https://github.com/twingly/twingly-analytics-api-ruby/issues/11)
- Use the rspec-its gem [\#11](https://github.com/twingly/twingly-search-api-ruby/issues/11)

**Merged pull requests:**

- Fix deprecations [\#14](https://github.com/twingly/twingly-analytics-api-ruby/pull/14) ([walro](https://github.com/walro))
- Support Ruby 2.2 [\#13](https://github.com/twingly/twingly-analytics-api-ruby/pull/13) ([dentarg](https://github.com/dentarg))
- Use Faraday instead of Net::HTTP directly [\#9](https://github.com/twingly/twingly-analytics-api-ruby/pull/9) ([jage](https://github.com/jage))
- Fix deprecations [\#14](https://github.com/twingly/twingly-search-api-ruby/pull/14) ([walro](https://github.com/walro))
- Support Ruby 2.2 [\#13](https://github.com/twingly/twingly-search-api-ruby/pull/13) ([dentarg](https://github.com/dentarg))
- Use Faraday instead of Net::HTTP directly [\#9](https://github.com/twingly/twingly-search-api-ruby/pull/9) ([jage](https://github.com/jage))

## [1.0.0](https://github.com/twingly/twingly-analytics-api-ruby/tree/1.0.0) (2014-10-30)
## [1.0.0](https://github.com/twingly/twingly-search-api-ruby/tree/1.0.0) (2014-10-30)
**Implemented enhancements:**

- Use HTTPS for API access [\#7](https://github.com/twingly/twingly-analytics-api-ruby/issues/7)
- Remove swedish comment [\#5](https://github.com/twingly/twingly-analytics-api-ruby/issues/5)
- Rewrite history to remove huge vcr-cassettes [\#4](https://github.com/twingly/twingly-analytics-api-ruby/issues/4)
- Remove humongous vcr cassettes [\#1](https://github.com/twingly/twingly-analytics-api-ruby/issues/1)
- Use HTTPS for API access [\#7](https://github.com/twingly/twingly-search-api-ruby/issues/7)
- Remove swedish comment [\#5](https://github.com/twingly/twingly-search-api-ruby/issues/5)
- Rewrite history to remove huge vcr-cassettes [\#4](https://github.com/twingly/twingly-search-api-ruby/issues/4)
- Remove humongous vcr cassettes [\#1](https://github.com/twingly/twingly-search-api-ruby/issues/1)

**Closed issues:**

- Add a LICENSE [\#6](https://github.com/twingly/twingly-analytics-api-ruby/issues/6)
- Wrap lines at 72 characters [\#2](https://github.com/twingly/twingly-analytics-api-ruby/issues/2)
- Add a LICENSE [\#6](https://github.com/twingly/twingly-search-api-ruby/issues/6)
- Wrap lines at 72 characters [\#2](https://github.com/twingly/twingly-search-api-ruby/issues/2)

**Merged pull requests:**

- Refactor to improve readability [\#3](https://github.com/twingly/twingly-analytics-api-ruby/pull/3) ([jage](https://github.com/jage))
- Refactor to improve readability [\#3](https://github.com/twingly/twingly-search-api-ruby/pull/3) ([jage](https://github.com/jage))



\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ A Ruby gem for Twingly's Search API (previously known as Analytics API). Twingly
Install via RubyGems

```Shell
gem install twingly-analytics
gem install twingly-search
```

Or add to your application's [Gemfile](http://bundler.io/gemfile.html) and then run `bundle`

```Ruby
gem 'twingly-analytics'
gem 'twingly-search'
```

## Usage

```Ruby
require 'twingly-analytics'
require 'twingly/search'

client = Twingly::Analytics::Client.new
client = Twingly::Search::Client.new
query = client.query
query.pattern = 'github page-size:10'
query.language = 'sv'
result = query.execute
=> #<Twingly::Analytics::Result:0x3ff7adcbe3d4 @posts, @number_of_matches_returned=10, @number_of_matches_total=3035221>
=> #<Twingly::Search::Result:0x3ff7adcbe3d4 @posts, @number_of_matches_returned=10, @number_of_matches_total=3035221>
result.posts # will include all returned posts
```

The `twinlgy-analytics` gem talks to a commercial blog search API and requires an API key. Best practice is to set the `TWINGLY_ANALYTICS_KEY` environment variable to the obtained key. `Twingly::Analytics::Client` can be passed a key at initialization if your setup does not allow environment variables.
The `twingly-search` gem talks to a commercial blog search API and requires an API key. Best practice is to set the `TWINGLY_SEARCH_KEY` environment variable to the obtained key. `Twingly::Search::Client` can be passed a key at initialization if your setup does not allow environment variables.

Example code can be found in [examples/](examples/).

Expand All @@ -47,11 +47,11 @@ Too learn more about the capabilities of this API you should read the [Twingly S
## Development and release

1. Make sure the master branch has an up-to-date changelog. Generate with `rake changelog`. Set `CHANGELOG_GITHUB_TOKEN` to a personal access token to increase the API rate limit. (The changelog uses [GitHub Changelog Generator](https://github.com/skywinder/github-changelog-generator/))
1. Bump version in `lib/twingly-analytics/version.rb`, follow [Semantic Versioning 2.0.0](http://semver.org/)
1. Bump version in `lib/twingly/search/version.rb`, follow [Semantic Versioning 2.0.0](http://semver.org/)
1. Build and release gem with `bundle exec rake release`. This will create a git tag for the version and push the `.gem` file to https://rubygems.org/.
1. Update release information on the [releases page].

[releases page]: https://github.com/twingly/twingly-analytics-api-ruby/releases
[releases page]: https://github.com/twingly/twingly-search-api-ruby/releases

## License

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ end
require "github_changelog_generator/task"
GitHubChangelogGenerator::RakeTask.new(:changelog) do |config|
config.user = "twingly"
config.project = "twingly-analytics-api-ruby"
config.project = "twingly-search-api-ruby"
end

desc "Synonym for spec"
Expand Down
2 changes: 1 addition & 1 deletion examples/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source 'https://rubygems.org'

gem 'twingly-analytics', path: '../'
gem 'twingly-search', path: '../'
8 changes: 4 additions & 4 deletions examples/find_all_posts_mentioning_github.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Bundler.require

class AnalyticsPostStream
class SearchPostStream
def initialize(keyword, language: nil)
# Set environment variable TWINGLY_ANALYTICS_KEY
client = Twingly::Analytics::Client.new
# Set environment variable TWINGLY_SEARCH_KEY
client = Twingly::Search::Client.new
@query = client.query
@query.language = language
@query.pattern = "sort-order:asc sort:published #{keyword}"
Expand All @@ -23,7 +23,7 @@ def each
end
end

stream = AnalyticsPostStream.new("(github) AND (hipchat OR slack)")
stream = SearchPostStream.new("(github) AND (hipchat OR slack)")
stream.each do |post|
puts post.url
end
4 changes: 2 additions & 2 deletions examples/hello_world.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Bundler.require

# Set environment variable TWINGLY_ANALYTICS_KEY
client = Twingly::Analytics::Client.new
# Set environment variable TWINGLY_SEARCH_KEY
client = Twingly::Search::Client.new
query = client.query
query.pattern = '"hello world"'
query.start_time = Time.now - (24 * 3600) # search last day
Expand Down
6 changes: 0 additions & 6 deletions lib/twingly-analytics.rb

This file was deleted.

5 changes: 0 additions & 5 deletions lib/twingly-analytics/version.rb

This file was deleted.

6 changes: 6 additions & 0 deletions lib/twingly/search.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'twingly/search/client'
require 'twingly/search/query'
require 'twingly/search/result'
require 'twingly/search/parser'
require 'twingly/search/post'
require 'twingly/search/version'
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Twingly
module Analytics
module Search
class Client
attr_accessor :api_key

Expand All @@ -12,7 +12,7 @@ def query
end
private
def env_api_key
ENV['TWINGLY_ANALYTICS_KEY']
ENV['TWINGLY_SEARCH_KEY']
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'nokogiri'

module Twingly
module Analytics
module Search
class Parser
def parse(document)
result = Result.new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'date'

module Twingly
module Analytics
module Search
class Post
attr_reader :url, :title, :summary, :language_code, :indexed,
:published, :blog_url, :blog_name, :authority, :blog_rank, :tags
Expand Down
10 changes: 5 additions & 5 deletions lib/twingly-analytics/query.rb → lib/twingly/search/query.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
require 'faraday'

module Twingly
module Analytics
module Search
class Query
attr_accessor :pattern, :language, :client, :start_time, :end_time

BASE_URL = 'https://api.twingly.com'
ANALYTICS_PATH = '/analytics/Analytics.ashx'
SEARCH_PATH = '/analytics/Analytics.ashx'

def initialize(client)
@client = client
end

def url
"#{BASE_URL}#{ANALYTICS_PATH}?#{url_parameters}"
"#{BASE_URL}#{SEARCH_PATH}?#{url_parameters}"
end

def execute
Expand Down Expand Up @@ -52,8 +52,8 @@ def get_response
faraday.request :url_encoded
faraday.adapter Faraday.default_adapter
end
connection.headers[:user_agent] = "Twingly Analytics Ruby Client/#{VERSION}"
connection.get(ANALYTICS_PATH, request_parameters)
connection.headers[:user_agent] = "Twingly Search Ruby Client/#{VERSION}"
connection.get(SEARCH_PATH, request_parameters)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Twingly
module Analytics
module Search
class Result
attr_accessor :number_of_matches_returned, :number_of_matches_total,
:seconds_elapsed
Expand Down
5 changes: 5 additions & 0 deletions lib/twingly/search/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Twingly
module Search
VERSION = "3.0.0"
end
end
2 changes: 1 addition & 1 deletion spec/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

include Twingly::Analytics
include Twingly::Search

describe Client do
subject { Client.new('api_key') }
Expand Down
2 changes: 1 addition & 1 deletion spec/parser_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

include Twingly::Analytics
include Twingly::Search

describe Parser do
it { should respond_to(:parse) }
Expand Down
2 changes: 1 addition & 1 deletion spec/post_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

include Twingly::Analytics
include Twingly::Search

describe Post do
it { should respond_to :url }
Expand Down
2 changes: 1 addition & 1 deletion spec/query_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'
require 'vcr_setup'

include Twingly::Analytics
include Twingly::Search

describe Query do

Expand Down
2 changes: 1 addition & 1 deletion spec/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'rspec/its'
require 'uri'

include Twingly::Analytics
include Twingly::Search

describe Result do
it { should respond_to :posts }
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require File.dirname(__FILE__) + '/../lib/twingly-analytics'
require File.dirname(__FILE__) + '/../lib/twingly/search'
2 changes: 1 addition & 1 deletion spec/vcr_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
VCR.configure do |c|
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
c.hook_into :webmock
c.filter_sensitive_data('api_key') { ENV['TWINGLY_ANALYTICS_KEY'] }
c.filter_sensitive_data('api_key') { ENV['TWINGLY_SEARCH_KEY'] }
end
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# encoding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'twingly-analytics/version'
require 'twingly/search/version'

Gem::Specification.new do |spec|
spec.name = "twingly-analytics"
spec.version = Twingly::Analytics::VERSION
spec.name = "twingly-search"
spec.version = Twingly::Search::VERSION
spec.platform = Gem::Platform::RUBY
spec.authors = ["Johan Eckerström"]
spec.email = ["johan.eckerstrom@twingly.com"]
spec.homepage = "http://github.com/twingly/twingly-analytics-api-ruby"
spec.summary = "Ruby API client for Twingly Analytics"
spec.description = "Twingly Analytics is a product from Twingly AB"
spec.authors = ["Twingly AB"]
spec.email = ["support@twingly.com"]
spec.homepage = "http://github.com/twingly/twingly-search-api-ruby"
spec.summary = "Ruby API client for Twingly Search"
spec.description = "Twingly Search is a product from Twingly AB"
spec.license = 'MIT'
spec.required_ruby_version = ">= 1.9.3"

Expand Down