wykop 0.6

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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.travis.yml +5 -0
  4. data/Contributors.md +0 -0
  5. data/Gemfile +8 -0
  6. data/README.md +52 -0
  7. data/Rakefile +8 -0
  8. data/TODO.md +7 -0
  9. data/doc/diggs/add.md +7 -0
  10. data/doc/diggs/favorites.md +17 -0
  11. data/doc/diggs/links.md +14 -0
  12. data/doc/diggs/observatory.md +15 -0
  13. data/doc/diggs/popular.md +14 -0
  14. data/doc/diggs/related.md +20 -0
  15. data/doc/diggs/stream.md +25 -0
  16. data/doc/diggs/tag.md +41 -0
  17. data/doc/diggs/tags.md +11 -0
  18. data/doc/diggs/top.md +44 -0
  19. data/doc/index.md +18 -0
  20. data/doc/search.md +44 -0
  21. data/doc/user/basic.md +81 -0
  22. data/doc/user/link.md +14 -0
  23. data/doc/user/pm.md +13 -0
  24. data/doc/user/rank.md +12 -0
  25. data/lib/wykop.rb +8 -0
  26. data/lib/wykop/client.rb +77 -0
  27. data/lib/wykop/configuration.rb +29 -0
  28. data/lib/wykop/error.rb +14 -0
  29. data/lib/wykop/operations/add.rb +22 -0
  30. data/lib/wykop/operations/favorites.rb +27 -0
  31. data/lib/wykop/operations/link.rb +55 -0
  32. data/lib/wykop/operations/links.rb +18 -0
  33. data/lib/wykop/operations/message.rb +30 -0
  34. data/lib/wykop/operations/observatory.rb +35 -0
  35. data/lib/wykop/operations/popular.rb +18 -0
  36. data/lib/wykop/operations/rank.rb +23 -0
  37. data/lib/wykop/operations/related.rb +24 -0
  38. data/lib/wykop/operations/request.rb +39 -0
  39. data/lib/wykop/operations/search.rb +42 -0
  40. data/lib/wykop/operations/stream.rb +26 -0
  41. data/lib/wykop/operations/tag.rb +33 -0
  42. data/lib/wykop/operations/tags.rb +17 -0
  43. data/lib/wykop/operations/top.rb +52 -0
  44. data/lib/wykop/operations/user.rb +55 -0
  45. data/lib/wykop/version.rb +3 -0
  46. data/spec/spec_helper.rb +16 -0
  47. data/spec/user_spec.rb +70 -0
  48. data/wykop.gemspec +26 -0
  49. metadata +141 -0
@@ -0,0 +1,42 @@
1
+ module Wykop
2
+ module Operations
3
+ class Search
4
+ # Documentation: http://www.wykop.pl/dla-programistow/dokumentacja/#info6_6_1
5
+ def initialize(client)
6
+ @client = client
7
+ @request = Wykop::Operations::Request.new(@client)
8
+ end
9
+
10
+ def search_index( p = {} )
11
+ if ! p.has_key?(:page); p[:page] = 0; end
12
+ return @request.execute(replace_url( { :banana => 'search', :potato => 'index', :page => p[:page] } ), { 'q' => p[:q] })
13
+ end
14
+
15
+ def search_entries( p = {} )
16
+ if ! p.has_key?(:page); p[:page] = 0; end
17
+ return @request.execute(replace_url( { :banana => 'search', :potato => 'entries', :page => p[:page] } ), { 'q' => p[:q] })
18
+ end
19
+
20
+ def search_profiles( p = {} )
21
+ if ! p.has_key?(:page); p[:page] = 0; end
22
+ return @request.execute(replace_url( { :banana => 'search', :potato => 'profiles', :page => p[:page] } ), { 'q' => p[:q] })
23
+ end
24
+
25
+ def search_links( p = {} )
26
+ if ! p.has_key?(:page); p[:page] = 0; end
27
+ p.delete(:page)
28
+ return @request.execute(replace_url( { :banana => 'search', :potato => 'links', :page => p[:page] } ), p)
29
+ end
30
+
31
+ def replace_url( p = {} )
32
+ standard_url = "#{@client.configuration.api_host}/banana/potato/appkey,#{@client.configuration.app_user_key}/userkey,#{@client.user_info['userkey']}/paged"
33
+ if ! p.has_key?(:page)
34
+ standard_url = standard_url.gsub(/\/paged/, '')
35
+ else
36
+ standard_url = standard_url.gsub(/paged/, "page,#{p[:page]}")
37
+ end
38
+ return standard_url.gsub(/banana/, p[:banana]).gsub(/potato/, p[:potato])
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ module Wykop
2
+ module Operations
3
+ class Stream
4
+ # Documentation: http://www.wykop.pl/dla-programistow/dokumentacja/#info6_16
5
+ def initialize(client)
6
+ @client = client
7
+ @request = Wykop::Operations::Request.new(@client)
8
+ end
9
+
10
+ def stream_show( p = {} )
11
+ if ! p.has_key?(:page); p[:page] = 0; end
12
+ return @request.execute(replace_url({ :banana => 'stream', :potato => 'index', :page => p[:page]} ), Hash.new)
13
+ end
14
+
15
+ def stream_hot( p = {} )
16
+ if ! p.has_key?(:page); p[:page] = 0; end
17
+ return @request.execute(replace_url({ :banana => 'stream', :potato => 'hot', :page => p[:page]} ), Hash.new)
18
+ end
19
+
20
+ def replace_url(p = {} )
21
+ standard_url = "#{@client.configuration.api_host}/banana/potato/appkey,#{@client.configuration.app_user_key}/userkey,#{@client.user_info['userkey']}/page,#{p[:page]}"
22
+ return standard_url.gsub(/banana/, p[:banana]).gsub(/potato/, p[:potato])
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,33 @@
1
+ module Wykop
2
+ module Operations
3
+ class Tag
4
+ # Documentation: http://www.wykop.pl/dla-programistow/dokumentacja/#info6_17
5
+ def initialize(client)
6
+ @client = client
7
+ @request = Wykop::Operations::Request.new(@client)
8
+ end
9
+
10
+ def tag_show( p = {} )
11
+ if ! p.has_key?(:page); p[:page] = 0; end
12
+ if ! p.has_key?(:type); p[:type] = 'index'; end
13
+ return @request.execute(@request.replace_url({ :banana => 'tag', :potato => p[:type], :param1 => p[:param1], :page => p[:page] } ), Hash.new)
14
+ end
15
+
16
+ def tag_observe( p = {} )
17
+ return @request.execute(@request.replace_url({ :banana => 'tag', :potato => 'observe', :param1 => p[:param1]}), Hash.new)
18
+ end
19
+
20
+ def tag_unobserve( p = {} )
21
+ return @request.execute(@request.replace_url({ :banana => 'tag', :potato => 'unobserve', :param1 => p[:param1]}), Hash.new)
22
+ end
23
+
24
+ def tag_block( p = {} )
25
+ return @request.execute(@request.replace_url({ :banana => 'tag', :potato => 'block', :param1 => p[:param1]}), Hash.new)
26
+ end
27
+
28
+ def tag_unblock( p = {} )
29
+ return @request.execute(@request.replace_url({ :banana => 'tag', :potato => 'unblock', :param1 => p[:param1]}), Hash.new)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ module Wykop
2
+ module Operations
3
+ class Tags
4
+ # Documentation: http://www.wykop.pl/dla-programistow/dokumentacja/#info6_19
5
+ def initialize(client)
6
+ @client = client
7
+ @request = Wykop::Operations::Request.new(@client)
8
+ end
9
+
10
+ def tags_show
11
+ q_url = @request.replace_url({ :banana => 'tags', :potato => 'index' })
12
+ q_body = Hash.new
13
+ return @request.execute(q_url, q_body)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,52 @@
1
+ require 'chronic'
2
+
3
+ module Wykop
4
+ module Operations
5
+ class Top
6
+ # Documentation: http://www.wykop.pl/dla-programistow/dokumentacja/#info6_8
7
+ def initialize(client)
8
+ @client = client
9
+ @request = Wykop::Operations::Request.new(@client)
10
+ end
11
+
12
+ def top_index( p = {} )
13
+ if ! p.has_key?(:year); p[:year] = Chronic.parse('last year').strftime("%Y"); end
14
+ q_url = replace_url({ :banana => 'top', :potato => 'index', :year => p[:year]})
15
+ q_body = Hash.new
16
+ @request.execute(q_url, q_body)
17
+ end
18
+
19
+ def top_date( p = {} )
20
+ if ! p.has_key?(:page); p[:page] = 0; end
21
+ if ! p.has_key?(:month); p[:month] = 1; end
22
+ if ! p.has_key?(:year); p[:year] = Chronic.parse('last year').strftime("%Y"); end
23
+ q_url = replace_url({ :banana => 'top', :potato => 'date' }.merge(p))
24
+ q_body = {'page' => p[:page]}
25
+ @request.execute(q_url, q_body)
26
+ end
27
+
28
+ def top_hits
29
+ q_url = replace_url({ :banana => 'top', :potato => 'hits'})
30
+ q_body = Hash.new
31
+ @request.execute(q_url, q_body)
32
+ end
33
+
34
+ def replace_url( p = {} )
35
+ # def replace_url(banana = nil, potato = nil, year = nil, month = nil)
36
+ standard_url = "#{@client.configuration.api_host}/banana/potato/param1/param2/appkey,#{@client.configuration.app_user_key}/userkey,#{@client.user_info['userkey']}"
37
+ # Checking parameters existence and removing them from url, just in case
38
+ if p.has_key?(:year)
39
+ standard_url = standard_url.gsub(/param1/, p[:year].to_s)
40
+ else
41
+ standard_url = standard_url.gsub(/\/param1/, '')
42
+ end
43
+ if p.has_key?(:month)
44
+ standard_url = standard_url.gsub(/param2/, p[:month].to_s)
45
+ else
46
+ standard_url = standard_url.gsub(/\/param2/, '')
47
+ end
48
+ return standard_url.gsub(/banana/, p[:banana]).gsub(/potato/, p[:potato])
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,55 @@
1
+ module Wykop
2
+ module Operations
3
+ class User
4
+ # Documentation: http://www.wykop.pl/dla-programistow/dokumentacja/#info6_7
5
+ def initialize(client)
6
+ @client = client
7
+ @request = Wykop::Operations::Request.new(@client)
8
+ end
9
+
10
+ def login
11
+ # Opening new connection to wykop API. It returns configuration hash and all the client information
12
+ @client.user_info = login_request
13
+ if @client.user_info.nil?
14
+ return false
15
+ end
16
+ return true
17
+ end
18
+
19
+ def info(what = nil)
20
+ # Getting information about user account
21
+ if what == nil
22
+ return @client.user_info
23
+ else
24
+ return @client.user_info[what]
25
+ end
26
+ end
27
+
28
+ def favorites()
29
+ # Listing favourites for current user
30
+ return @request.execute(@request.replace_url({:banana => 'user', :potato => 'favorites'}), Hash.new)
31
+ end
32
+
33
+ def observed()
34
+ # Listing observed for current user
35
+ return @request.execute(@request.replace_url({:banana => 'user', :potato => 'observed'}), Hash.new)
36
+ end
37
+
38
+ def tags()
39
+ # Listing observed for current user
40
+ return @request.execute(@request.replace_url({:banana => 'user', :potato => 'tags'}), Hash.new)
41
+ end
42
+
43
+ # Needs to be here, at least till i figure out where to put it
44
+
45
+ private
46
+
47
+ def login_request(params = nil)
48
+ # Building request URL
49
+ q_body = {'login' => @client.configuration.app_username, 'accountkey' => @client.configuration.app_generated_key}
50
+ q_url = "#{@client.configuration.api_host}/user/login/appkey,#{@client.configuration.app_user_key}"
51
+ @request.execute(q_url, q_body)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module Wykop
2
+ VERSION = "0.6"
3
+ end
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'wykop'
5
+ require 'rspec'
6
+
7
+ RSpec.configure do |c|
8
+ c.fail_fast = true
9
+ end
10
+
11
+ CFG_USER_KEY = ENV['WYKOP_CFG_USER_KEY']
12
+ CFG_USER_SECRET = ENV['WYKOP_CFG_USER_SECRET']
13
+ CFG_USER_NAME = ENV['WYKOP_CFG_USER_NAME']
14
+ CFG_GEN_SECRET = ENV['WYKOP_CFG_GEN_SECRET']
15
+
16
+ CLIENT = Wykop::Client.new({ app_user_key: CFG_USER_KEY, app_user_secret: CFG_USER_SECRET,app_username: CFG_USER_NAME, app_generated_key: CFG_GEN_SECRET, api_host: 'http://a.wykop.pl' })
@@ -0,0 +1,70 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "User session" do
4
+ it "have credentials" do
5
+ if ENV['WYKOP_CFG_USER_KEY'].empty? ||
6
+ ENV['WYKOP_CFG_USER_SECRET'].empty? ||
7
+ ENV['WYKOP_CFG_USER_NAME'].empty? ||
8
+ ENV['WYKOP_CFG_GEN_SECRET'].empty?
9
+ fail "No ENV credentials specified."
10
+ end
11
+ end
12
+
13
+ it "can check profile / log in" do
14
+ if CLIENT.login
15
+ client_request = CLIENT.info
16
+ if client_request.has_key?('error')
17
+ message = "Error! Code: #{client_request['error']['code']} => #{client_request['error']['message']}"
18
+ fail message
19
+ elsif client_request.nil?
20
+ fail "Can't log in"
21
+ end
22
+ end
23
+ end
24
+
25
+ # Checking all available methods
26
+ # We skip 'add_new' to avoid spamming
27
+ # We skip 'observatory_entries_comments' as it throws internal API error.
28
+ available_methods = CLIENT.methods(false).sort - [:link_bury, :add_new, :execute, :replace_url, :login, :observatory_entries_comments, :related_add]
29
+ available_methods.each do |mthd|
30
+ it "- method check: #{mthd}" do
31
+ params = nil
32
+ # Weird functions specific
33
+ if mthd.to_s == 'search_index'
34
+ params = { :q => 'potato' }
35
+ elsif mthd.to_s == 'search_profiles'
36
+ params = { :q => 'ouna-' }
37
+ elsif mthd.to_s =~ /related_vote_.*/
38
+ params = { :param1 => 2242488, :param2 => 27794764 }
39
+ elsif mthd.to_s == 'favorite_index'
40
+ params = { :param1 => 56072 }
41
+ elsif mthd.to_s =~ /messages_(read|delete)/
42
+ params = { :param1 => 'ouna-' }
43
+ elsif mthd.to_s == 'message_send'
44
+ params = { :param1 => 'ouna-', :body => 'test wykop gem' }
45
+ elsif mthd.to_s =~ /link_/
46
+ params = { :param1 => 2248060 }
47
+ elsif mthd.to_s == 'tag_show'
48
+ params = { :param1 => 'polityka', :type => 'entries' }
49
+ elsif mthd.to_s =~ /tag_.*(block|observe)/
50
+ params = { :param1 => 'polityka' }
51
+ end
52
+ if params.nil?
53
+ client_request = CLIENT.send(mthd)
54
+ else
55
+ client_request = CLIENT.send(mthd, params)
56
+ end
57
+ if client_request.is_a?(Hash)
58
+ # Wykop API throws errors only with Hash
59
+ if client_request.has_key?('error') || client_request =~ /.*<title>Ups...<\/title>.*/
60
+ if client_request['error']['code'].to_s =~ /!(112|1002)/
61
+ # Ignoring error 112 ( user doesn't accept messages )
62
+ # Ignoring error 1002 ( no controller to serve this query )
63
+ message = "Error! Code: #{client_request['error']['code']} => #{client_request['error']['message']}"
64
+ fail message
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wykop/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'wykop'
8
+ spec.version = Wykop::VERSION
9
+ spec.authors = ['Lukasz Raczylo']
10
+ spec.email = ['lukasz@raczylo.com']
11
+ spec.summary = %q{Ruby client library for wykop.pl API}
12
+ spec.description = 'Provides easy way to interact with the Wykop.pl API in any kind of application'
13
+ spec.homepage = 'https://github.com/lukaszraczylo/wykop-ruby'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ # Requirements
22
+ spec.required_ruby_version = '>=1.9.2'
23
+ spec.add_development_dependency 'bundler', '~> 1.5'
24
+ spec.add_development_dependency 'rake', '~> 10.0', '>= 10.0.0'
25
+ spec.add_development_dependency 'rspec', '~> 2.6'
26
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wykop
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.6'
5
+ platform: ruby
6
+ authors:
7
+ - Lukasz Raczylo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 10.0.0
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '10.0'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 10.0.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.6'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.6'
61
+ description: Provides easy way to interact with the Wykop.pl API in any kind of application
62
+ email:
63
+ - lukasz@raczylo.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - ".travis.yml"
70
+ - Contributors.md
71
+ - Gemfile
72
+ - README.md
73
+ - Rakefile
74
+ - TODO.md
75
+ - doc/diggs/add.md
76
+ - doc/diggs/favorites.md
77
+ - doc/diggs/links.md
78
+ - doc/diggs/observatory.md
79
+ - doc/diggs/popular.md
80
+ - doc/diggs/related.md
81
+ - doc/diggs/stream.md
82
+ - doc/diggs/tag.md
83
+ - doc/diggs/tags.md
84
+ - doc/diggs/top.md
85
+ - doc/index.md
86
+ - doc/search.md
87
+ - doc/user/basic.md
88
+ - doc/user/link.md
89
+ - doc/user/pm.md
90
+ - doc/user/rank.md
91
+ - lib/wykop.rb
92
+ - lib/wykop/client.rb
93
+ - lib/wykop/configuration.rb
94
+ - lib/wykop/error.rb
95
+ - lib/wykop/operations/add.rb
96
+ - lib/wykop/operations/favorites.rb
97
+ - lib/wykop/operations/link.rb
98
+ - lib/wykop/operations/links.rb
99
+ - lib/wykop/operations/message.rb
100
+ - lib/wykop/operations/observatory.rb
101
+ - lib/wykop/operations/popular.rb
102
+ - lib/wykop/operations/rank.rb
103
+ - lib/wykop/operations/related.rb
104
+ - lib/wykop/operations/request.rb
105
+ - lib/wykop/operations/search.rb
106
+ - lib/wykop/operations/stream.rb
107
+ - lib/wykop/operations/tag.rb
108
+ - lib/wykop/operations/tags.rb
109
+ - lib/wykop/operations/top.rb
110
+ - lib/wykop/operations/user.rb
111
+ - lib/wykop/version.rb
112
+ - spec/spec_helper.rb
113
+ - spec/user_spec.rb
114
+ - wykop.gemspec
115
+ homepage: https://github.com/lukaszraczylo/wykop-ruby
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: 1.9.2
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.4.3
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Ruby client library for wykop.pl API
139
+ test_files:
140
+ - spec/spec_helper.rb
141
+ - spec/user_spec.rb