hurriyet 0.0.0 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05f22fa971754bce6f74133e5ff9ba988a52cc75
4
- data.tar.gz: f1d85ed870fc23ebaf471c2602957d18c6237067
3
+ metadata.gz: 77a38e5cb97504aea7c46a832e05211ac4930d7a
4
+ data.tar.gz: 2ed376c6b2585d6ff3096e0487f4ae353ca1add8
5
5
  SHA512:
6
- metadata.gz: 736fc85fc07ef5b2efc0627aa762028bbae803e0724746ba65f0e9ffcc064e48e896782c1f86d8c897e1e9f45f4c72339709cc372a67f707d320f46d1bdecb62
7
- data.tar.gz: fd28c1ead9c0b28980504e2723020ddf12287a867b9c169a9e9e55d1a0460fb0e9b8299e4e93efd5994b5e6302dc75b75810c338e886582a5ac8877a702c67eb
6
+ metadata.gz: 9f6f9c6fe219c2d7f5fdcb3ddd2ef5d8e86e3935fc7ce2b64b4c52b8124ab8b9a869f8cb04e180284d1b1c2899838ab8aca2939129b5c6056330b1c24737d925
7
+ data.tar.gz: d71ab554f33ae55e889eea68dc602e1f37ad270d7d55a23844b5f7618a61be12da84ae9bb981a0e8d8f509d9175d918d62f554a422f96773698678617c07441c
@@ -1,4 +1,10 @@
1
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
+
2
8
  module Hurriyet
3
9
  class Client
4
10
  attr_accessor :apikey
@@ -9,5 +15,25 @@ module Hurriyet
9
15
  def articles
10
16
  Service::Article.new self
11
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
12
38
  end
13
39
  end
@@ -1,8 +1,8 @@
1
1
  module Hurriyet
2
2
  module ApiOperation
3
3
  module List
4
- def all
5
- execute endpoint
4
+ def all(options = {})
5
+ execute endpoint, options
6
6
  end
7
7
  end
8
8
  end
@@ -0,0 +1,10 @@
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
+
@@ -1,10 +1,9 @@
1
1
  require 'hurriyet/service/base'
2
- require 'hurriyet/service/api_operation/list'
3
2
  module Hurriyet
4
3
  module Service
5
4
  class Article < Base
6
- attr_accessor :client
7
5
  include ApiOperation::List
6
+ include ApiOperation::Show
8
7
 
9
8
  def endpoint
10
9
  'articles'
@@ -1,18 +1,44 @@
1
1
  require 'faraday'
2
+ require 'json'
3
+ require 'hurriyet/service/api_operation/list'
4
+ require 'hurriyet/service/api_operation/show'
2
5
  module Hurriyet
3
6
  module Service
4
7
  class Base
5
8
  attr_accessor :client
6
-
9
+ ALLOWED_PARAMETERS = %w(filter select top).map!(&:to_sym).freeze
7
10
  def initialize(client)
8
11
  @client = client
9
12
  @conn = Faraday.new(url: 'https://api.hurriyet.com.tr', headers: { apikey: @client.apikey })
10
13
  end
11
14
 
12
- def execute(endpoint)
13
- p @conn
14
- p "/#{version}/#{endpoint}"
15
- @conn.get("/#{version}/#{endpoint}").body
15
+ def execute(endpoint, options = {})
16
+ @options = options
17
+ @endpoint = endpoint
18
+ make_call
19
+ end
20
+
21
+ def make_call
22
+ resp = @conn.get(url)
23
+ JSON.parse(resp.body)
24
+ end
25
+
26
+ def url
27
+ "/#{version}/#{@endpoint}#{param_string}"
28
+ end
29
+
30
+ def param_string
31
+ string = ''
32
+ @options.each_with_index do |(key, value), index|
33
+ raise unless allowed?(key)
34
+ prefix = index == 0 ? '?' : '&'
35
+ string << "#{prefix}$#{key}=#{value}"
36
+ end
37
+ string
38
+ end
39
+
40
+ def allowed?(key)
41
+ ALLOWED_PARAMETERS.include? key
16
42
  end
17
43
 
18
44
  def version
@@ -0,0 +1,13 @@
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
@@ -0,0 +1,13 @@
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
@@ -0,0 +1,13 @@
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
@@ -0,0 +1,14 @@
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
+
@@ -0,0 +1,15 @@
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
+
15
+
data/lib/hurriyet.rb CHANGED
@@ -1,4 +1,3 @@
1
1
  require 'hurriyet/client'
2
- require 'hurriyet/service/article'
3
2
  module Hurriyet
4
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hurriyet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yigit Ozkavci
@@ -33,9 +33,14 @@ files:
33
33
  - lib/hurriyet.rb
34
34
  - lib/hurriyet/client.rb
35
35
  - lib/hurriyet/service/api_operation/list.rb
36
+ - lib/hurriyet/service/api_operation/show.rb
36
37
  - lib/hurriyet/service/article.rb
37
38
  - lib/hurriyet/service/base.rb
38
- - lib/main.rb
39
+ - lib/hurriyet/service/column.rb
40
+ - lib/hurriyet/service/news_photo_gallery.rb
41
+ - lib/hurriyet/service/page.rb
42
+ - lib/hurriyet/service/path.rb
43
+ - lib/hurriyet/service/writer.rb
39
44
  homepage: http://rubygems.org/gems/hurriyet
40
45
  licenses:
41
46
  - MIT
data/lib/main.rb DELETED
@@ -1,2 +0,0 @@
1
- require 'hurriyet.rb'
2
- h = Hurriyet::Client.new '9a9dcb9808624ac69e6c557a192afb33'