yify 0.0.2 → 0.0.3

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 (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -229
  3. data/lib/yify.rb +7 -3
  4. data/lib/yify/client.rb +307 -95
  5. data/lib/yify/models/actor.rb +6 -0
  6. data/lib/yify/models/api_response.rb +0 -2
  7. data/lib/yify/models/base.rb +18 -0
  8. data/lib/yify/models/bookmark.rb +6 -0
  9. data/lib/yify/models/comment.rb +1 -9
  10. data/lib/yify/models/director.rb +6 -0
  11. data/lib/yify/models/movie.rb +0 -48
  12. data/lib/yify/models/parental_guide.rb +6 -0
  13. data/lib/yify/models/profile.rb +1 -5
  14. data/lib/yify/models/review.rb +6 -0
  15. data/lib/yify/models/session.rb +0 -4
  16. data/lib/yify/models/torrent.rb +6 -0
  17. data/lib/yify/models/user.rb +1 -13
  18. data/lib/yify/response.rb +1 -12
  19. data/lib/yify/support/utils.rb +24 -1
  20. data/lib/yify/version.rb +1 -1
  21. data/spec/fixtures/vcr_cassettes/Yify_Client/should_add_a_movie_bookmark.yml +59 -0
  22. data/spec/fixtures/vcr_cassettes/Yify_Client/should_delete_a_comment.yml +59 -0
  23. data/spec/fixtures/vcr_cassettes/Yify_Client/should_delete_a_movie_bookmark.yml +59 -0
  24. data/spec/fixtures/vcr_cassettes/Yify_Client/should_edit_a_user_profile.yml +61 -0
  25. data/spec/fixtures/vcr_cassettes/Yify_Client/should_get_a_user_key.yml +59 -0
  26. data/spec/fixtures/vcr_cassettes/Yify_Client/should_get_a_user_profile.yml +56 -0
  27. data/spec/fixtures/vcr_cassettes/Yify_Client/should_get_movie_bookmarks.yml +59 -0
  28. data/spec/fixtures/vcr_cassettes/Yify_Client/should_get_movie_comments.yml +106 -60
  29. data/spec/fixtures/vcr_cassettes/Yify_Client/should_get_movie_details.yml +42 -29
  30. data/spec/fixtures/vcr_cassettes/Yify_Client/should_get_movie_parental_guides.yml +106 -0
  31. data/spec/fixtures/vcr_cassettes/Yify_Client/should_get_movie_reviews.yml +285 -0
  32. data/spec/fixtures/vcr_cassettes/Yify_Client/should_get_movie_suggestions.yml +69 -0
  33. data/spec/fixtures/vcr_cassettes/Yify_Client/should_get_upcoming_movies.yml +31 -159
  34. data/spec/fixtures/vcr_cassettes/Yify_Client/should_get_user_details.yml +35 -16
  35. data/spec/fixtures/vcr_cassettes/Yify_Client/should_like_a_comment.yml +59 -0
  36. data/spec/fixtures/vcr_cassettes/Yify_Client/should_like_a_movie.yml +59 -0
  37. data/spec/fixtures/vcr_cassettes/Yify_Client/should_list_movies.yml +36 -14
  38. data/spec/fixtures/vcr_cassettes/Yify_Client/should_make_a_comment.yml +60 -0
  39. data/spec/fixtures/vcr_cassettes/Yify_Client/should_make_a_request.yml +60 -0
  40. data/spec/fixtures/vcr_cassettes/Yify_Client/should_recover_forgotten_passwords.yml +59 -0
  41. data/spec/fixtures/vcr_cassettes/Yify_Client/should_register_a_user.yml +29 -12
  42. data/spec/fixtures/vcr_cassettes/Yify_Client/should_report_a_comment.yml +59 -0
  43. data/spec/fixtures/vcr_cassettes/Yify_Client/should_reset_a_password.yml +29 -12
  44. data/spec/models/base_spec.rb +21 -0
  45. data/spec/response_spec.rb +7 -11
  46. data/spec/spec_helper.rb +8 -4
  47. data/spec/yify_spec.rb +97 -57
  48. data/yify.gemspec +1 -1
  49. metadata +44 -38
  50. data/lib/yify/models/requested_movie.rb +0 -17
  51. data/lib/yify/models/upcoming_movie.rb +0 -15
  52. data/spec/fixtures/vcr_cassettes/Yify_Client/should_add_a_request.yml +0 -43
  53. data/spec/fixtures/vcr_cassettes/Yify_Client/should_edit_a_profile.yml +0 -42
  54. data/spec/fixtures/vcr_cassettes/Yify_Client/should_get_a_profile.yml +0 -44
  55. data/spec/fixtures/vcr_cassettes/Yify_Client/should_get_requests_list.yml +0 -52
  56. data/spec/fixtures/vcr_cassettes/Yify_Client/should_login_a_user.yml +0 -42
  57. data/spec/fixtures/vcr_cassettes/Yify_Client/should_post_a_comment.yml +0 -42
  58. data/spec/fixtures/vcr_cassettes/Yify_Client/should_recover_passwords.yml +0 -42
  59. data/spec/fixtures/vcr_cassettes/Yify_Client/should_vote_on_requests.yml +0 -42
  60. data/spec/models/api_response_spec.rb +0 -6
  61. data/spec/models/comment_spec.rb +0 -13
  62. data/spec/models/movie_spec.rb +0 -53
  63. data/spec/models/profile_spec.rb +0 -21
  64. data/spec/models/requested_movie_spec.rb +0 -20
  65. data/spec/models/session_spec.rb +0 -8
  66. data/spec/models/upcoming_movie_spec.rb +0 -13
  67. data/spec/models/user_spec.rb +0 -17
@@ -0,0 +1,6 @@
1
+ module Yify
2
+ module Models
3
+ class Actor < Base
4
+ end
5
+ end
6
+ end
@@ -1,8 +1,6 @@
1
1
  module Yify
2
2
  module Models
3
3
  class ApiResponse < Base
4
- attribute :status, String
5
- attribute :error, String
6
4
  end
7
5
  end
8
6
  end
@@ -4,6 +4,24 @@ module Yify
4
4
  module Models
5
5
  class Base
6
6
  include Virtus.model
7
+ include Yify::Support::Utils
8
+
9
+ def initialize(params)
10
+ self.extend(Virtus.model)
11
+
12
+ params.each do |key, value|
13
+ klass = map_class(key)
14
+
15
+ begin Yify::Models.const_get klass.to_s.classify
16
+ attribute key, Array[Yify::Models.const_get klass.to_s.classify]
17
+ rescue
18
+ attribute key, value.class
19
+ end
20
+
21
+ self[key] = value
22
+ end
23
+ end
24
+
7
25
  end
8
26
  end
9
27
  end
@@ -0,0 +1,6 @@
1
+ module Yify
2
+ module Models
3
+ class Bookmark < Base
4
+ end
5
+ end
6
+ end
@@ -1,15 +1,7 @@
1
1
  module Yify
2
2
  module Models
3
3
  class Comment < Base
4
- attribute :comment_id, Integer
5
- attribute :comment_text, String
6
- attribute :date_added, DateTime
7
- attribute :date_added_epoch, DateTime
8
- attribute :user_id, Integer
9
- attribute :parent_comment_id, Integer
10
- attribute :user_name, String
11
- attribute :user_avatar, String
12
- attribute :user_group, String
13
4
  end
14
5
  end
15
6
  end
7
+
@@ -0,0 +1,6 @@
1
+ module Yify
2
+ module Models
3
+ class Director < Base
4
+ end
5
+ end
6
+ end
@@ -1,54 +1,6 @@
1
1
  module Yify
2
2
  module Models
3
3
  class Movie < Base
4
- attribute :age_rating, String
5
- attribute :cast_list, String
6
- attribute :cover_image, String
7
- attribute :date_uploaded, DateTime
8
- attribute :date_uploaded_epoch, DateTime
9
- attribute :director_list, String
10
- attribute :downloaded, Integer
11
- attribute :frame_rate, Float
12
- attribute :genre, String
13
- attribute :genre1, String
14
- attribute :genre2, String
15
- attribute :imdb_code, String
16
- attribute :imdb_link, String
17
- attribute :language, String
18
- attribute :large_cover, String
19
- attribute :large_screenshot1, String
20
- attribute :large_screenshot2, String
21
- attribute :large_screenshot3, String
22
- attribute :long_description, String
23
- attribute :medium_cover, String
24
- attribute :medium_screenshot1, String
25
- attribute :medium_screenshot2, String
26
- attribute :medium_screenshot3, String
27
- attribute :movie_count, String
28
- attribute :movie_id, Integer
29
- attribute :movie_rating, Float
30
- attribute :movie_runtime, Integer
31
- attribute :movie_title, String
32
- attribute :movie_title_clean, String
33
- attribute :movie_url, String
34
- attribute :movie_year, String
35
- attribute :quality, String
36
- attribute :resolution, String
37
- attribute :short_description, String
38
- attribute :size, String
39
- attribute :size_byte, Integer
40
- attribute :state, String
41
- attribute :subtitles, String
42
- attribute :torrent_hash, String
43
- attribute :torrent_magnet_url, String
44
- attribute :torrent_peers, String
45
- attribute :torrent_seeds, String
46
- attribute :torrent_url, String
47
- attribute :uploader, String
48
- attribute :uploader_uid, Integer
49
- attribute :uploader_notes, String
50
- attribute :youtube_trailer_id, String
51
- attribute :youtube_trailer_url, String
52
4
  end
53
5
  end
54
6
  end
@@ -0,0 +1,6 @@
1
+ module Yify
2
+ module Models
3
+ class ParentalGuide < Base
4
+ end
5
+ end
6
+ end
@@ -1,10 +1,6 @@
1
1
  module Yify
2
2
  module Models
3
- class Profile < User
4
- attribute :num_of_votes_left
5
- attribute :profile_active
6
- attribute :ip_address
7
- attribute :num_of_requests_left
3
+ class Profile < Base
8
4
  end
9
5
  end
10
6
  end
@@ -0,0 +1,6 @@
1
+ module Yify
2
+ module Models
3
+ class Review < Base
4
+ end
5
+ end
6
+ end
@@ -1,10 +1,6 @@
1
1
  module Yify
2
2
  module Models
3
3
  class Session < Base
4
- attribute :hash, String
5
- attribute :user_id, Integer
6
- attribute :user_role, String
7
- attribute :username, String
8
4
  end
9
5
  end
10
6
  end
@@ -0,0 +1,6 @@
1
+ module Yify
2
+ module Models
3
+ class Torrent < Base
4
+ end
5
+ end
6
+ end
@@ -1,19 +1,7 @@
1
1
  module Yify
2
2
  module Models
3
3
  class User < Base
4
- attribute :about, String
5
- attribute :avatar, String
6
- attribute :chat_time_seconds, Integer
7
- attribute :comment_count, Integer
8
- attribute :join_dated, DateTime
9
- attribute :join_dated_epoch, DateTime
10
- attribute :last_seen_date, DateTime
11
- attribute :last_seen_date_epoch, DateTime
12
- attribute :movies_requested_count, Integer
13
- attribute :torrents_downloaded_count, Integer
14
- attribute :user_id, Integer
15
- attribute :user_name, String
16
- attribute :user_role, String
17
4
  end
18
5
  end
19
6
  end
7
+
@@ -16,7 +16,7 @@ module Yify
16
16
 
17
17
  def normalized_response
18
18
  result = symbolize_keys(@response)
19
- result = extract(result, @model)
19
+ result = extract(result[:data] || result, @model)
20
20
 
21
21
  @result.clear
22
22
  @result = hydrate_model(result)
@@ -44,17 +44,6 @@ module Yify
44
44
  value
45
45
  end
46
46
  end
47
-
48
- def map_class(model)
49
- case model
50
- when :movie_list
51
- "movie"
52
- when :request_list
53
- "requested_movie"
54
- else
55
- model
56
- end
57
- end
58
47
 
59
48
  end
60
49
  end
@@ -14,7 +14,13 @@ module Yify
14
14
  if value.is_a?(Hash)
15
15
  new_value = symbolize_keys(value)
16
16
  elsif value.is_a?(Array)
17
- new_value = value.map{ |item| symbolize_keys(item) }
17
+ new_value = value.map do |item|
18
+ if item.is_a?(Hash)
19
+ symbolize_keys(item)
20
+ else
21
+ item
22
+ end
23
+ end
18
24
  else
19
25
  new_value = value
20
26
  end
@@ -25,6 +31,23 @@ module Yify
25
31
  end
26
32
  end
27
33
 
34
+ def map_class(name)
35
+ case name
36
+ when :recently_downloaded
37
+ :movie
38
+ when :movies
39
+ :movie
40
+ when :request_list
41
+ :movie
42
+ when :upcoming_movies
43
+ :movie
44
+ when :movie_suggestions
45
+ :movie
46
+ else
47
+ name
48
+ end
49
+ end
50
+
28
51
  end
29
52
  end
30
53
  end
@@ -1,3 +1,3 @@
1
1
  module Yify
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,59 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://yts.to/api/v2/add_movie_bookmark
6
+ body:
7
+ encoding: UTF-8
8
+ string: application_key=<APPLICATION_KEY>&user_key=<USER_KEY>&movie_id=353
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Sun, 20 Sep 2015 21:12:19 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ Cache-Control:
32
+ - public, s-maxage=21600
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Pragma:
36
+ - no-cache
37
+ Expires:
38
+ - "-1"
39
+ X-Frame-Options:
40
+ - SAMEORIGIN
41
+ - SAMEORIGIN
42
+ X-Content-Type-Options:
43
+ - nosniff
44
+ - nosniff
45
+ Age:
46
+ - '0'
47
+ X-Cache:
48
+ - uncached
49
+ Accept-Ranges:
50
+ - bytes
51
+ X-Frontend:
52
+ - DE
53
+ body:
54
+ encoding: UTF-8
55
+ string: '{"status":"ok","status_message":"Movie has been successfully bookmarked","data":{"user_id":<USER_ID>"movie_id":353},"@meta":{"server_time":1442783539,"server_timezone":"Pacific\/Auckland","api_version":2,"execution_time":"9.55
56
+ ms"}}'
57
+ http_version:
58
+ recorded_at: Sun, 20 Sep 2015 21:12:19 GMT
59
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,59 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://yts.to/api/v2/delete_comment
6
+ body:
7
+ encoding: UTF-8
8
+ string: application_key=<APPLICATION_KEY>&user_key=<USER_KEY>&comment_id=379208
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Sun, 20 Sep 2015 21:37:21 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ Cache-Control:
32
+ - public, s-maxage=21600
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Pragma:
36
+ - no-cache
37
+ Expires:
38
+ - "-1"
39
+ X-Frame-Options:
40
+ - SAMEORIGIN
41
+ - SAMEORIGIN
42
+ X-Content-Type-Options:
43
+ - nosniff
44
+ - nosniff
45
+ Age:
46
+ - '0'
47
+ X-Cache:
48
+ - uncached
49
+ Accept-Ranges:
50
+ - bytes
51
+ X-Frontend:
52
+ - CA
53
+ body:
54
+ encoding: UTF-8
55
+ string: '{"status":"ok","status_message":"Comment has been successfully deleted","data":{"comment_id":379208,"user_id":1247782},"@meta":{"server_time":1442785041,"server_timezone":"Pacific\/Auckland","api_version":2,"execution_time":"6.67
56
+ ms"}}'
57
+ http_version:
58
+ recorded_at: Sun, 20 Sep 2015 21:37:21 GMT
59
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,59 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://yts.to/api/v2/delete_movie_bookmark
6
+ body:
7
+ encoding: UTF-8
8
+ string: application_key=<APPLICATION_KEY>&user_key=<USER_KEY>&movie_id=353
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Sun, 20 Sep 2015 21:22:47 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ Cache-Control:
32
+ - public, s-maxage=21600
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Pragma:
36
+ - no-cache
37
+ Expires:
38
+ - "-1"
39
+ X-Frame-Options:
40
+ - SAMEORIGIN
41
+ - SAMEORIGIN
42
+ X-Content-Type-Options:
43
+ - nosniff
44
+ - nosniff
45
+ Age:
46
+ - '0'
47
+ X-Cache:
48
+ - uncached
49
+ Accept-Ranges:
50
+ - bytes
51
+ X-Frontend:
52
+ - CA
53
+ body:
54
+ encoding: UTF-8
55
+ string: '{"status":"ok","status_message":"Movie bookmarked has been removed","data":{"user_id":<USER_ID>"movie_id":353},"@meta":{"server_time":1442784167,"server_timezone":"Pacific\/Auckland","api_version":2,"execution_time":"6.07
56
+ ms"}}'
57
+ http_version:
58
+ recorded_at: Sun, 20 Sep 2015 21:22:48 GMT
59
+ recorded_with: VCR 2.9.3