├── .rubocop.yml ├── lib ├── hurriyet.rb └── hurriyet │ ├── version.rb │ ├── service │ ├── api_operation │ │ ├── list.rb │ │ └── show.rb │ ├── page.rb │ ├── path.rb │ ├── column.rb │ ├── writer.rb │ ├── article.rb │ ├── news_photo_gallery.rb │ └── base.rb │ └── client.rb ├── Gemfile ├── .travis.yml ├── Rakefile ├── spec ├── lib │ ├── hurriyet_spec.rb │ └── hurriyet │ │ └── client_spec.rb ├── services │ ├── column_spec.rb │ ├── page_spec.rb │ ├── path_spec.rb │ ├── writer_spec.rb │ ├── article_spec.rb │ └── news_photo_gallery_spec.rb ├── service_helper.rb ├── spec_helper.rb └── support │ └── shared_examples_for_api_operations.rb ├── hurriyet.gemspec ├── LICENSE.md ├── Gemfile.lock └── README.md /.rubocop.yml: -------------------------------------------------------------------------------- 1 | Documentation: 2 | Enabled: False 3 | -------------------------------------------------------------------------------- /lib/hurriyet.rb: -------------------------------------------------------------------------------- 1 | require 'hurriyet/client' 2 | module Hurriyet 3 | end 4 | -------------------------------------------------------------------------------- /lib/hurriyet/version.rb: -------------------------------------------------------------------------------- 1 | module Hurriyet 2 | VERSION = '0.2.1'.freeze 3 | end 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in your-gem.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.2.0 4 | script: 5 | - bundle exec rubocop 6 | - bundle exec rspec 7 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rspec/core/rake_task' 2 | 3 | RSpec::Core::RakeTask.new('spec') 4 | 5 | # If you want to make this the default task 6 | task default: :spec 7 | -------------------------------------------------------------------------------- /spec/lib/hurriyet_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'hurriyet/version' 3 | 4 | describe Hurriyet::VERSION do 5 | it { is_expected.to match(/\d+\.\d+\.\d+/) } 6 | end 7 | -------------------------------------------------------------------------------- /lib/hurriyet/service/api_operation/list.rb: -------------------------------------------------------------------------------- 1 | module Hurriyet 2 | module ApiOperation 3 | module List 4 | def all(options = {}) 5 | execute endpoint, options 6 | end 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/hurriyet/service/api_operation/show.rb: -------------------------------------------------------------------------------- 1 | module Hurriyet 2 | module ApiOperation 3 | module Show 4 | def single(id, options = {}) 5 | execute "#{endpoint}/#{id}", options 6 | end 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /spec/services/column_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'hurriyet/service/column' 3 | 4 | module Hurriyet 5 | module Service 6 | describe Column do 7 | it_behaves_like 'list includer' 8 | it_behaves_like 'show includer' 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/hurriyet/service/page.rb: -------------------------------------------------------------------------------- 1 | require 'hurriyet/service/base' 2 | module Hurriyet 3 | module Service 4 | class Page < Base 5 | include ApiOperation::List 6 | include ApiOperation::Show 7 | 8 | def endpoint 9 | 'pages' 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/hurriyet/service/path.rb: -------------------------------------------------------------------------------- 1 | require 'hurriyet/service/base' 2 | module Hurriyet 3 | module Service 4 | class Path < Base 5 | include ApiOperation::List 6 | include ApiOperation::Show 7 | 8 | def endpoint 9 | 'paths' 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/hurriyet/service/column.rb: -------------------------------------------------------------------------------- 1 | require 'hurriyet/service/base' 2 | module Hurriyet 3 | module Service 4 | class Column < Base 5 | include ApiOperation::List 6 | include ApiOperation::Show 7 | 8 | def endpoint 9 | 'columns' 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/hurriyet/service/writer.rb: -------------------------------------------------------------------------------- 1 | require 'hurriyet/service/base' 2 | module Hurriyet 3 | module Service 4 | class Writer < Base 5 | include ApiOperation::List 6 | include ApiOperation::Show 7 | 8 | def endpoint 9 | 'writers' 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/hurriyet/service/article.rb: -------------------------------------------------------------------------------- 1 | require 'hurriyet/service/base' 2 | module Hurriyet 3 | module Service 4 | class Article < Base 5 | include ApiOperation::List 6 | include ApiOperation::Show 7 | 8 | def endpoint 9 | 'articles' 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /spec/services/page_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'hurriyet/service/page' 3 | 4 | module Hurriyet 5 | module Service 6 | describe Page do 7 | it_behaves_like 'service' 8 | it_behaves_like 'list includer' 9 | it_behaves_like 'show includer' 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /spec/services/path_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'hurriyet/service/path' 3 | 4 | module Hurriyet 5 | module Service 6 | describe Path do 7 | it_behaves_like 'service' 8 | it_behaves_like 'list includer' 9 | it_behaves_like 'show includer' 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /spec/services/writer_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'hurriyet/service/writer' 3 | 4 | module Hurriyet 5 | module Service 6 | describe Writer do 7 | it_behaves_like 'service' 8 | it_behaves_like 'list includer' 9 | it_behaves_like 'show includer' 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /spec/services/article_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'hurriyet/service/article' 3 | 4 | module Hurriyet 5 | module Service 6 | describe Article do 7 | it_behaves_like 'service' 8 | it_behaves_like 'list includer' 9 | it_behaves_like 'show includer' 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/hurriyet/service/news_photo_gallery.rb: -------------------------------------------------------------------------------- 1 | require 'hurriyet/service/base' 2 | module Hurriyet 3 | module Service 4 | class NewsPhotoGallery < Base 5 | include ApiOperation::List 6 | include ApiOperation::Show 7 | 8 | def endpoint 9 | 'newsphotogalleries' 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /spec/services/news_photo_gallery_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'hurriyet/service/news_photo_gallery' 3 | 4 | module Hurriyet 5 | module Service 6 | describe NewsPhotoGallery do 7 | it_behaves_like 'service' 8 | it_behaves_like 'list includer' 9 | it_behaves_like 'show includer' 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /spec/service_helper.rb: -------------------------------------------------------------------------------- 1 | require 'hurriyet/service/api_operation/list' 2 | RSpec::Matchers.define :include_operation do |expected| 3 | match do |actual| 4 | actual.class.included_modules.include?(operation_class(expected)) 5 | end 6 | end 7 | 8 | def operation_class(name) 9 | case name 10 | when 'list' 11 | Hurriyet::ApiOperation::List 12 | when 'show' 13 | Hurriyet::ApiOperation::Show 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'hurriyet' 2 | require 'service_helper' 3 | require 'simplecov' 4 | SimpleCov.start 5 | RSpec.configure do |config| 6 | config.expect_with :rspec do |expectations| 7 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 8 | end 9 | 10 | config.mock_with :rspec do |mocks| 11 | mocks.verify_partial_doubles = true 12 | end 13 | end 14 | Dir['./spec/support/**/*.rb'].sort.each { |f| require f } 15 | -------------------------------------------------------------------------------- /spec/lib/hurriyet/client_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | module Hurriyet 4 | describe Client do 5 | let(:apikey) { 'some_api_key' } 6 | let(:client) { Client.new apikey } 7 | let(:services) do 8 | %w(articles columns news_photo_galleries pages paths writers) 9 | end 10 | 11 | it 'has api key' do 12 | expect(client).to respond_to(:apikey) 13 | end 14 | 15 | it 'returns services' do 16 | services.each do |r| 17 | expect(client).to respond_to(r) 18 | service = client.send(r) 19 | expect(service.class.name.split('::')[1]).to eq('Service') 20 | end 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /spec/support/shared_examples_for_api_operations.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'service_helper' 3 | require 'hurriyet/client' 4 | 5 | shared_examples_for 'service' do 6 | let(:client) { Hurriyet::Client.new 'some_api_key' } 7 | subject { described_class.new client } 8 | 9 | it { is_expected.to respond_to(:endpoint) } 10 | end 11 | 12 | shared_examples_for 'list includer' do 13 | let(:client) { Hurriyet::Client.new 'some_api_key' } 14 | subject { described_class.new client } 15 | 16 | it { is_expected.to include_operation('list') } 17 | end 18 | 19 | shared_examples_for 'show includer' do 20 | let(:client) { Hurriyet::Client.new 'some_api_key' } 21 | subject { described_class.new client } 22 | 23 | it { is_expected.to include_operation('show') } 24 | end 25 | -------------------------------------------------------------------------------- /hurriyet.gemspec: -------------------------------------------------------------------------------- 1 | require_relative 'lib/hurriyet/version' 2 | Gem::Specification.new do |s| 3 | s.name = 'hurriyet' 4 | s.version = Hurriyet::VERSION 5 | s.date = '2016-09-09' 6 | s.summary = 'Hurriyet API Wrapper' 7 | s.description = 'Ruby wrapper for developers.hurriyet.com API.' 8 | s.authors = ['Yigit Ozkavci'] 9 | s.email = 'yigitozkavci8@gmail.com' 10 | s.files = Dir['lib/**/*.rb'] 11 | s.homepage = 'http://rubygems.org/gems/hurriyet' 12 | s.license = 'MIT' 13 | 14 | s.required_ruby_version = '>= 2.2.0' 15 | 16 | s.add_dependency 'faraday', '0.9.2' 17 | 18 | s.add_development_dependency 'rspec', '~> 3.3' 19 | s.add_development_dependency 'rubocop', '~> 0.42' 20 | s.add_development_dependency 'simplecov', '~> 0.12' 21 | end 22 | -------------------------------------------------------------------------------- /lib/hurriyet/client.rb: -------------------------------------------------------------------------------- 1 | require 'hurriyet/service/article' 2 | require 'hurriyet/service/column' 3 | require 'hurriyet/service/news_photo_gallery' 4 | require 'hurriyet/service/page' 5 | require 'hurriyet/service/path' 6 | require 'hurriyet/service/writer' 7 | 8 | module Hurriyet 9 | class Client 10 | attr_accessor :apikey 11 | def initialize(apikey) 12 | @apikey = apikey 13 | end 14 | 15 | def articles 16 | Service::Article.new self 17 | end 18 | 19 | def columns 20 | Service::Column.new self 21 | end 22 | 23 | def news_photo_galleries 24 | Service::NewsPhotoGallery.new self 25 | end 26 | 27 | def pages 28 | Service::Page.new self 29 | end 30 | 31 | def paths 32 | Service::Path.new self 33 | end 34 | 35 | def writers 36 | Service::Writer.new self 37 | end 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Yiğit Özkavcı 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /lib/hurriyet/service/base.rb: -------------------------------------------------------------------------------- 1 | require 'faraday' 2 | require 'json' 3 | require 'hurriyet/service/api_operation/list' 4 | require 'hurriyet/service/api_operation/show' 5 | module Hurriyet 6 | module Service 7 | class Base 8 | attr_accessor :client 9 | ALLOWED_PARAMETERS = %w(filter select top).map(&:to_sym).freeze 10 | VERSION = 'v1'.freeze 11 | 12 | def initialize(client) 13 | @client = client 14 | @conn = Faraday.new url: 'https://api.hurriyet.com.tr', 15 | headers: { apikey: @client.apikey } 16 | end 17 | 18 | def execute(endpoint, options = {}) 19 | @options = options 20 | @endpoint = endpoint 21 | make_call 22 | end 23 | 24 | def make_call 25 | resp = @conn.get(url) 26 | JSON.parse(resp.body) 27 | end 28 | 29 | def url 30 | "/#{VERSION}/#{@endpoint}#{param_string}" 31 | end 32 | 33 | def param_string 34 | string = '' 35 | @options.each_with_index do |(key, value), index| 36 | raise unless parameter_allowed?(key) 37 | prefix = index.zero? ? '?' : '&' 38 | string << "#{prefix}$#{key}=#{value}" 39 | end 40 | string 41 | end 42 | 43 | def parameter_allowed?(key) 44 | ALLOWED_PARAMETERS.include? key 45 | end 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | hurriyet (0.2.1) 5 | faraday (= 0.9.2) 6 | 7 | GEM 8 | remote: https://rubygems.org/ 9 | specs: 10 | ast (2.3.0) 11 | diff-lcs (1.2.5) 12 | docile (1.1.5) 13 | faraday (0.9.2) 14 | multipart-post (>= 1.2, < 3) 15 | json (2.0.2) 16 | multipart-post (2.0.0) 17 | parser (2.3.1.2) 18 | ast (~> 2.2) 19 | powerpack (0.1.1) 20 | rainbow (2.1.0) 21 | rspec (3.5.0) 22 | rspec-core (~> 3.5.0) 23 | rspec-expectations (~> 3.5.0) 24 | rspec-mocks (~> 3.5.0) 25 | rspec-core (3.5.3) 26 | rspec-support (~> 3.5.0) 27 | rspec-expectations (3.5.0) 28 | diff-lcs (>= 1.2.0, < 2.0) 29 | rspec-support (~> 3.5.0) 30 | rspec-mocks (3.5.0) 31 | diff-lcs (>= 1.2.0, < 2.0) 32 | rspec-support (~> 3.5.0) 33 | rspec-support (3.5.0) 34 | rubocop (0.42.0) 35 | parser (>= 2.3.1.1, < 3.0) 36 | powerpack (~> 0.1) 37 | rainbow (>= 1.99.1, < 3.0) 38 | ruby-progressbar (~> 1.7) 39 | unicode-display_width (~> 1.0, >= 1.0.1) 40 | ruby-progressbar (1.8.1) 41 | simplecov (0.12.0) 42 | docile (~> 1.1.0) 43 | json (>= 1.8, < 3) 44 | simplecov-html (~> 0.10.0) 45 | simplecov-html (0.10.0) 46 | unicode-display_width (1.1.1) 47 | 48 | PLATFORMS 49 | ruby 50 | 51 | DEPENDENCIES 52 | hurriyet! 53 | rspec (~> 3.3) 54 | rubocop (~> 0.42) 55 | simplecov (~> 0.12) 56 | 57 | BUNDLED WITH 58 | 1.12.5 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hurriyet-ruby 2 | ![Gem Version](https://img.shields.io/gem/v/hurriyet.svg) 3 | ![Test Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen.svg) 4 | ![Travis CI](https://img.shields.io/travis/yigitozkavci/hurriyet-ruby.svg) 5 | 6 | Unofficial Ruby Wrapper for Hurriyet API - http://developers.hurriyet.com.tr/ 7 | 8 | ## Getting Started 9 | 10 | ### Installation 11 | 12 | `$ gem install hurriyet` 13 | 14 | ### Usage 15 | ```ruby 16 | require 'hurriyet' 17 | 18 | client = Hurriyet::Client.new() 19 | client.articles.all 20 | ``` 21 | 22 | ## Table of Contents 23 | ### Resources 24 | 25 | - [Articles](#articles) 26 | - [Columns](#columns) 27 | - [News Photo Galleries](#news-photo-galleries) 28 | - [Pages](#pages) 29 | - [Paths](#paths) 30 | - [Writers](#writers) 31 | 32 | ### Other 33 | 34 | - [Parameters](#parameters) 35 | 36 | ## Resources 37 | ### Articles 38 | 39 | ```ruby 40 | # Get all articles 41 | client.articles.all 42 | ``` 43 | 44 | ```ruby 45 | # Get a single article 46 | client.articles.single(40220736) 47 | ``` 48 | 49 | ### Columns 50 | 51 | ```ruby 52 | # Get all columns 53 | client.columns.all 54 | ``` 55 | 56 | ```ruby 57 | # Get a single column 58 | client.columns.single(40220397) 59 | ``` 60 | 61 | ## News Photo Galleries 62 | 63 | ```ruby 64 | # Get all galleries 65 | client.news_photo_galleries.all 66 | ``` 67 | 68 | ```ruby 69 | # Get a single gallery 70 | client.news_photo_galleries.single(40220735) 71 | ``` 72 | 73 | ## Pages 74 | 75 | ```ruby 76 | # Get all pages 77 | client.pages.all 78 | ``` 79 | 80 | ```ruby 81 | # Get a single page 82 | client.pages.single('55e861bc6534652c108afa2f') 83 | ``` 84 | 85 | ## Paths 86 | 87 | ```ruby 88 | # Get all paths 89 | client.paths.all 90 | ``` 91 | 92 | ```ruby 93 | # Get a single path 94 | client.paths.single('563cddcc67b0a934e44ee2d7') 95 | ``` 96 | 97 | ## Writers 98 | 99 | ```ruby 100 | # Get all writers 101 | client.writers.all 102 | ``` 103 | 104 | ```ruby 105 | # Get a single writer 106 | client.writers.single('570167e867b0a90bdc503452') 107 | ``` 108 | 109 | # Parameters 110 | Hurriyet API allows you to filter, select and limit the resources you fetch. Here is how: 111 | 112 | - **$select**: Select only 1 column from incoming resources. 113 | - **$top**: Limit response resources. 114 | - **$filter**: Filter incoming resources. See [here](http://www.odata.org/getting-started/basic-tutorial/#queryData) for more info. 115 | 116 | ```ruby 117 | # Takes 3 articles. 118 | client.articles.all top: 3 119 | 120 | # Takes 3 articles of which path equals to 'gundem' 121 | client.articles.all top: 4, filter: 'Path eq \'gundem\'' 122 | 123 | # Selects title of articles of which title contains word 'Istanbul' 124 | client.articles.all filter: 'contains(Title, \'Istanbul\')', select: 'Title' 125 | ``` 126 | 127 | # LICENSE 128 | This project is licensed under the terms of the [MIT license](https://github.com/yigitozkavci/hurriyet-ruby/blob/master/LICENSE.md). 129 | --------------------------------------------------------------------------------