flickrie 0.6.1 → 0.7.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.
Files changed (90) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG.md +22 -0
  3. data/Gemfile +0 -6
  4. data/README.md +15 -1
  5. data/Rakefile +8 -13
  6. data/api_methods.md +1 -1
  7. data/flickrie.gemspec +2 -3
  8. data/lib/flickrie/api_methods.rb +17 -0
  9. data/lib/flickrie/client.rb +21 -5
  10. data/lib/flickrie/instance.rb +7 -2
  11. data/lib/flickrie/license.rb +2 -0
  12. data/lib/flickrie/location.rb +10 -8
  13. data/lib/flickrie/media/exif.rb +3 -1
  14. data/lib/flickrie/media/tag.rb +3 -3
  15. data/lib/flickrie/media/visibility.rb +6 -4
  16. data/lib/flickrie/media.rb +69 -84
  17. data/lib/flickrie/media_count.rb +3 -5
  18. data/lib/flickrie/photo.rb +55 -54
  19. data/lib/flickrie/set.rb +31 -25
  20. data/lib/flickrie/ticket.rb +4 -8
  21. data/lib/flickrie/upload_client.rb +7 -2
  22. data/lib/flickrie/user.rb +33 -34
  23. data/lib/flickrie/version.rb +1 -1
  24. data/lib/flickrie/video.rb +13 -12
  25. data/spec/api_methods_spec.rb +43 -0
  26. data/spec/error_spec.rb +32 -0
  27. data/{test → spec/files}/photo.jpg +0 -0
  28. data/{test → spec/files}/video.mov +0 -0
  29. data/spec/instance_spec.rb +22 -0
  30. data/spec/license_spec.rb +15 -0
  31. data/spec/location_spec.rb +11 -0
  32. data/spec/media_count_spec.rb +18 -0
  33. data/spec/media_spec.rb +271 -0
  34. data/spec/oauth_spec.rb +22 -0
  35. data/spec/photo_spec.rb +137 -0
  36. data/spec/set_spec.rb +68 -0
  37. data/spec/spec_helper.rb +68 -0
  38. data/spec/user_spec.rb +56 -0
  39. data/spec/video_spec.rb +54 -0
  40. metadata +47 -132
  41. data/test/error_test.rb +0 -20
  42. data/test/instance_test.rb +0 -20
  43. data/test/license_test.rb +0 -19
  44. data/test/location_test.rb +0 -29
  45. data/test/media_count_test.rb +0 -25
  46. data/test/media_test.rb +0 -432
  47. data/test/oauth_test.rb +0 -25
  48. data/test/photo_test.rb +0 -212
  49. data/test/set_test.rb +0 -92
  50. data/test/test_helper.rb +0 -14
  51. data/test/user_test.rb +0 -70
  52. data/test/vcr_cassettes/error/code.yml +0 -1165
  53. data/test/vcr_cassettes/instance/calling_api_methods.yml +0 -182
  54. data/test/vcr_cassettes/license/get_licenses.yml +0 -73
  55. data/test/vcr_cassettes/location/square_brackets.yml +0 -85
  56. data/test/vcr_cassettes/media/delete.yml +0 -1380
  57. data/test/vcr_cassettes/media/from_contacts.yml +0 -155
  58. data/test/vcr_cassettes/media/from_set.yml +0 -276
  59. data/test/vcr_cassettes/media/from_user.yml +0 -275
  60. data/test/vcr_cassettes/media/get_context.yml +0 -73
  61. data/test/vcr_cassettes/media/get_info.yml +0 -167
  62. data/test/vcr_cassettes/media/remove_tag.yml +0 -264
  63. data/test/vcr_cassettes/media/replace.yml +0 -2252
  64. data/test/vcr_cassettes/media/search.yml +0 -275
  65. data/test/vcr_cassettes/media/tags.yml +0 -346
  66. data/test/vcr_cassettes/media_count/get.yml +0 -135
  67. data/test/vcr_cassettes/media_count/square_brackets.yml +0 -69
  68. data/test/vcr_cassettes/oauth/tokens.yml +0 -400
  69. data/test/vcr_cassettes/photo/asynchronous_upload.yml +0 -1693
  70. data/test/vcr_cassettes/photo/from_set.yml +0 -273
  71. data/test/vcr_cassettes/photo/from_user.yml +0 -275
  72. data/test/vcr_cassettes/photo/get_exif.yml +0 -239
  73. data/test/vcr_cassettes/photo/get_sizes.yml +0 -147
  74. data/test/vcr_cassettes/photo/other_api_calls.yml +0 -506
  75. data/test/vcr_cassettes/photo/search.yml +0 -271
  76. data/test/vcr_cassettes/photo/square_brackets.yml +0 -85
  77. data/test/vcr_cassettes/photo/upload.yml +0 -1229
  78. data/test/vcr_cassettes/set/from_user.yml +0 -477
  79. data/test/vcr_cassettes/set/get_info.yml +0 -951
  80. data/test/vcr_cassettes/set/square_brackets.yml +0 -73
  81. data/test/vcr_cassettes/user/find_by_email_or_username.yml +0 -135
  82. data/test/vcr_cassettes/user/get_info.yml +0 -151
  83. data/test/vcr_cassettes/user/square_brackets.yml +0 -77
  84. data/test/vcr_cassettes/video/get_exif.yml +0 -135
  85. data/test/vcr_cassettes/video/get_info.yml +0 -86
  86. data/test/vcr_cassettes/video/get_sizes.yml +0 -151
  87. data/test/vcr_cassettes/video/other_api_calls.yml +0 -643
  88. data/test/vcr_cassettes/video/square_brackets.yml +0 -86
  89. data/test/vcr_cassettes/video/upload.yml +0 -308
  90. data/test/video_test.rb +0 -118
@@ -6,8 +6,8 @@ module Flickrie
6
6
 
7
7
  SIZES = {
8
8
  'Square 75' => 'sq',
9
- 'Square 150' => 'q',
10
9
  'Thumbnail' => 't',
10
+ 'Square 150' => 'q',
11
11
  'Small 240' => 's',
12
12
  'Small 320' => 'n',
13
13
  'Medium 500' => 'm',
@@ -17,68 +17,70 @@ module Flickrie
17
17
  'Original' => 'o'
18
18
  }
19
19
 
20
- def square!(number); @size = "Square #{number}"; self end
21
- def thumbnail!; @size = "Thumbnail"; self end
22
- def small!(number); @size = "Small #{number}"; self end
23
- def medium!(number); @size = "Medium #{number}"; self end
24
- def large!(number); @size = "Large #{number}"; self end
25
- def original!; @size = "Original"; self end
26
-
27
- def square(number); dup.square!(number) end
28
- def thumbnail; dup.thumbnail! end
29
- def small(number); dup.small!(number) end
30
- def medium(number); dup.medium!(number) end
31
- def large(number); dup.large!(number) end
32
- def original; dup.original! end
33
-
34
- [75, 150].each do |n|
35
- define_method("square#{n}!") { square!(n) }
36
- define_method("square#{n}") { square(n) }
37
- end
38
- [240, 320].each do |n|
39
- define_method("small#{n}!") { small!(n) }
40
- define_method("small#{n}") { small(n) }
41
- end
42
- [500, 640, 800].each do |n|
43
- define_method("medium#{n}!") { medium!(n) }
44
- define_method("medium#{n}") { medium(n) }
45
- end
46
- [1024].each do |n|
47
- define_method("large#{n}!") { large!(n) }
48
- define_method("large#{n}") { large(n) }
49
- end
50
-
51
- def largest!; @size = largest_size; self end
52
- def largest; dup.largest! end
20
+ def square!(number) @size = "Square #{number}"; self end
21
+ def thumbnail!() @size = "Thumbnail"; self end
22
+ def small!(number) @size = "Small #{number}"; self end
23
+ def medium!(number) @size = "Medium #{number}"; self end
24
+ def large!(number) @size = "Large #{number}"; self end
25
+ def original!() @size = "Original"; self end
26
+
27
+ def square(number) dup.square!(number) end
28
+ def thumbnail() dup.thumbnail! end
29
+ def small(number) dup.small!(number) end
30
+ def medium(number) dup.medium!(number) end
31
+ def large(number) dup.large!(number) end
32
+ def original() dup.original! end
33
+
34
+ #--
35
+ # Alternate size methods
36
+ def square75() square(75) end
37
+ def square75!() square!(75) end
38
+ def square150() square(150) end
39
+ def square150!() square!(150) end
40
+ def small240() small(240) end
41
+ def small240!() small!(240) end
42
+ def small320() small(320) end
43
+ def small320!() small!(320) end
44
+ def medium500() medium(500) end
45
+ def medium500!() medium!(500) end
46
+ def medium640() medium(640) end
47
+ def medium640!() medium!(640) end
48
+ def medium800() medium(800) end
49
+ def medium800!() medium!(800) end
50
+ def large1024() large(1024) end
51
+ def large1024!() large!(1024) end
52
+
53
+ def largest!() @size = largest_size; self end
54
+ def largest() dup.largest! end
53
55
 
54
56
  def available_sizes
55
- SIZES.select { |_, s| @info["url_#{s}"] }.keys
57
+ SIZES.select { |_,v| @info["url_#{v}"] }.keys
56
58
  end
57
59
 
58
- def width; @info["width_#{size_abbr}"].to_i if @info["width_#{size_abbr}"] end
59
- def height; @info["height_#{size_abbr}"].to_i if @info["height_#{size_abbr}"] end
60
-
61
- def source_url; @info["url_#{size_abbr}"] end
60
+ def width() Integer(@info["width_#{size_abbr}"]) rescue nil end
61
+ def height() Integer(@info["height_#{size_abbr}"]) rescue nil end
62
+ def source_url() @info["url_#{size_abbr}"] end
62
63
 
63
- def rotation; @info['rotation'].to_i if @info['rotation'] end
64
+ def rotation() Integer(@info['rotation']) rescue nil end
64
65
 
65
- def get_sizes(info = nil)
66
- info ||= Flickrie.client.get_media_sizes(id).body['sizes']
66
+ def get_sizes(params = {}, info = nil)
67
+ info ||= Flickrie.client.get_media_sizes(id, params).body['sizes']
68
+ @info['usage'] ||= {}
67
69
  @info['usage'].update \
68
70
  'canblog' => info['canblog'],
69
71
  'canprint' => info['canprint'],
70
72
  'candownload' => info['candownload']
71
73
  flickr_sizes = {
72
- 'Square' => 'sq',
73
- 'Large Square' => 'q',
74
- 'Thumbnail' => 't',
75
- 'Small' => 's',
76
- 'Small 320' => 'n',
77
- 'Medium' => 'm',
78
- 'Medium 640' => 'z',
79
- 'Medium 800' => 'c',
80
- 'Large' => 'l',
81
- 'Original' => 'o'
74
+ 'Square' => SIZES['Square 75'],
75
+ 'Large Square' => SIZES['Square 150'],
76
+ 'Thumbnail' => SIZES['Thumbnail'],
77
+ 'Small' => SIZES['Small 240'],
78
+ 'Small 320' => SIZES['Small 320'],
79
+ 'Medium' => SIZES['Medium 500'],
80
+ 'Medium 640' => SIZES['Medium 640'],
81
+ 'Medium 800' => SIZES['Medium 800'],
82
+ 'Large' => SIZES['Large 1024'],
83
+ 'Original' => SIZES['Original']
82
84
  }
83
85
  info['size'].each do |size_info|
84
86
  size_abbr = flickr_sizes[size_info['label']]
@@ -87,8 +89,7 @@ module Flickrie
87
89
  @info["url_#{size_abbr}"] = size_info['source']
88
90
  end
89
91
 
90
- @size = largest_size
91
- self
92
+ largest!
92
93
  end
93
94
 
94
95
  private
data/lib/flickrie/set.rb CHANGED
@@ -1,39 +1,43 @@
1
1
  module Flickrie
2
2
  class Set
3
- def id; @info['id'] end
4
- def secret; @info['secret'] end
5
- def server; @info['server'] end
6
- def farm; @info['farm'] end
7
- def title; @info['title'] end
8
- def description; @info['description'] end
9
-
10
- def primary_media_id; @info['primary'] end
3
+ def id() @info['id'] end
4
+ def secret() @info['secret'] end
5
+ def server() @info['server'] end
6
+ def farm() @info['farm'] end
7
+ def title() @info['title'] end
8
+ def description() @info['description'] end
9
+
10
+ def primary_media_id() @info['primary'] end
11
11
  alias primary_photo_id primary_media_id
12
12
  alias primary_video_id primary_media_id
13
13
 
14
- def views_count; @info['count_views'].to_i if @info['count_views'] end
15
- def comments_count; @info['count_comments'].to_i if @info['count_comments'] end
16
- def photos_count; @info['count_photos'].to_i if @info['count_photos'] end
17
- def videos_count; @info['count_videos'].to_i if @info['count_videos'] end
18
- def media_count; photos_count + videos_count rescue nil end
14
+ def views_count() Integer(@info['count_views']) rescue nil end
15
+ def comments_count() Integer(@info['count_comments']) rescue nil end
16
+ def photos_count() Integer(@info['count_photos']) rescue nil end
17
+ def videos_count() Integer(@info['count_videos']) rescue nil end
18
+ def media_count
19
+ photos_count + videos_count rescue nil
20
+ end
19
21
 
20
- def owner; User.new('nsid' => @info['owner']) if @info['owner'] end
22
+ def owner() User.new('nsid' => @info['owner']) if @info['owner'] end
21
23
 
22
- def photos(params = {}); Flickrie.photos_from_set(id, params) end
23
- def videos(params = {}); Flickrie.videos_from_set(id, params) end
24
- def media(params = {}); Flickrie.media_from_set(id, params) end
24
+ def photos(params = {}) Flickrie.photos_from_set(id, params) end
25
+ def videos(params = {}) Flickrie.videos_from_set(id, params) end
26
+ def media(params = {}) Flickrie.media_from_set(id, params) end
25
27
 
26
- def can_comment?; @info['can_comment'].to_i == 1 if @info['can_comment'] end
28
+ def can_comment?() Integer(@info['can_comment']) == 1 rescue nil end
27
29
 
28
30
  #--
29
31
  # TODO: Figure out what this is
30
- def needs_interstitial?; @info['needs_interstitial'].to_i == 1 end
31
- def visibility_can_see_set?; @info['visibility_can_see_set'].to_i == 1 end
32
+ def needs_interstitial?() Integer(@info['needs_interstitial']) == 1 rescue nil end
33
+ def visibility_can_see_set?() Integer(@info['visibility_can_see_set']) == 1 rescue nil end
32
34
 
33
- def created_at; Time.at(@info['date_create'].to_i) end
34
- def updated_at; Time.at(@info['date_update'].to_i) end
35
+ def created_at() Time.at(Integer(@info['date_create'])) rescue nil end
36
+ def updated_at() Time.at(Integer(@info['date_update'])) rescue nil end
35
37
 
36
- def url; "http://www.flickr.com/photos/#{owner.nsid}/sets/#{id}" end
38
+ def url
39
+ "http://www.flickr.com/photos/#{owner.nsid}/sets/#{id}"
40
+ end
37
41
 
38
42
  def [](key)
39
43
  @info[key]
@@ -41,10 +45,12 @@ module Flickrie
41
45
 
42
46
  def get_info(info = nil)
43
47
  info ||= Flickrie.client.get_set_info(id).body['photoset']
44
- info['title'] = info['title']['_content']
45
- info['description'] = info['description']['_content']
46
48
  @info.update(info)
47
49
 
50
+ # Fixes
51
+ @info['title'] = @info['title']['_content']
52
+ @info['description'] = @info['description']['_content']
53
+
48
54
  self
49
55
  end
50
56
 
@@ -1,17 +1,13 @@
1
1
  module Flickrie
2
2
  class Ticket
3
- def id; @info['id'] end
4
- def media_id; @info['photoid'] end
3
+ def id() @info['id'] end
4
+ def media_id() @info['photoid'] end
5
5
  alias photo_id media_id
6
6
  alias video_id media_id
7
7
 
8
- def complete?
9
- @info['complete'].to_i == 1
10
- end
8
+ def complete?() Integer(@info['complete']) == 1 rescue nil end
11
9
 
12
- def imported_at
13
- Time.at(@info['imported'].to_i)
14
- end
10
+ def imported_at() Time.at(Integer(@info['imported'])) rescue nil end
15
11
 
16
12
  def [](key)
17
13
  @info[key]
@@ -1,7 +1,11 @@
1
1
  module Flickrie
2
2
  class << self
3
- def upload_client(access_token_hash = {})
4
- @upload_client ||= UploadClient.new(upload_params) do |conn|
3
+ def upload_client
4
+ @upload_client ||= new_upload_client
5
+ end
6
+
7
+ def new_upload_client(access_token_hash = {})
8
+ UploadClient.new(upload_params) do |conn|
5
9
  conn.use FaradayMiddleware::OAuth,
6
10
  :consumer_key => api_key,
7
11
  :consumer_secret => shared_secret,
@@ -11,6 +15,7 @@ module Flickrie
11
15
 
12
16
  conn.use UploadStatusCheck
13
17
  conn.use FaradayMiddleware::ParseXml
18
+ conn.use OAuthStatusCheck
14
19
 
15
20
  conn.adapter Faraday.default_adapter
16
21
  end
data/lib/flickrie/user.rb CHANGED
@@ -2,19 +2,19 @@ require 'date'
2
2
 
3
3
  module Flickrie
4
4
  class User
5
- def id; @info['id'] end
6
- def nsid; @info['nsid'] end
7
- def username; @info['username'] end
8
- def real_name; @info['realname'] end
9
- def location; @info['location'] end
10
- def time_zone; @info['timezone'] end
11
- def description; @info['description'] end
12
- def profile_url; @info['profileurl'] end
13
- def mobile_url; @info['mobileurl'] end
14
- def photos_url; @info['photosurl'] end
15
- def path_alias; @info['path_alias'] end
16
- def icon_server; @info['iconserver'] end
17
- def icon_farm; @info['iconfarm'] end
5
+ def id() @info['id'] end
6
+ def nsid() @info['nsid'] end
7
+ def username() @info['username'] end
8
+ def real_name() @info['realname'] end
9
+ def location() @info['location'] end
10
+ def time_zone() @info['timezone'] end
11
+ def description() @info['description'] end
12
+ def profile_url() @info['profileurl'] end
13
+ def mobile_url() @info['mobileurl'] end
14
+ def photos_url() @info['photosurl'] end
15
+ def path_alias() @info['path_alias'] end
16
+ def icon_server() @info['iconserver'] end
17
+ def icon_farm() @info['iconfarm'] end
18
18
 
19
19
  def buddy_icon_url
20
20
  if icon_farm
@@ -26,36 +26,29 @@ module Flickrie
26
26
  end
27
27
  end
28
28
 
29
- def first_taken
30
- if @info['photos'] and @info['photos']['firstdatetaken']
31
- DateTime.parse(@info['photos']['firstdatetaken']).to_time
32
- end
33
- end
29
+ def first_taken() DateTime.parse(@info['photos']['firstdatetaken']).to_time rescue nil end
30
+ def first_uploaded() Time.at(Integer(@info['photos']['firstdate'])) rescue nil end
34
31
 
35
- def first_uploaded
36
- if @info['photos'] and @info['photos']['firstdate']
37
- Time.at(@info['photos']['firstdate'].to_i)
38
- end
39
- end
32
+ def favorited_at() Time.at(Integer(@info['favedate'])) rescue nil end
40
33
 
41
- def media_count
42
- if @info['photos'] and @info['photos']['count']
43
- @info['photos']['count'].to_i
44
- end
34
+ def favorited_at
35
+ Time.at(@info['favedate'].to_i)
45
36
  end
46
37
 
47
- def public_photos; Flickrie.public_photos_from_user(nsid) end
38
+ def media_count() Integer(@info['photos']['count']) rescue nil end
39
+ alias photos_count media_count
40
+ alias videos_count media_count
48
41
 
49
- def pro?
50
- @info['ispro'].to_i == 1 if @info['ispro']
51
- end
42
+ def public_photos() Flickrie.public_photos_from_user(nsid) end
43
+
44
+ def pro?() Integer(@info['ispro']) == 1 rescue nil end
52
45
 
53
46
  def [](key)
54
47
  @info[key]
55
48
  end
56
49
 
57
- def get_info(info = nil)
58
- info ||= Flickrie.client.get_user_info(nsid).body['person']
50
+ def get_info(params = {}, info = nil)
51
+ info ||= Flickrie.client.get_user_info(nsid, params).body['person']
59
52
  @info.update(info)
60
53
 
61
54
  %w[username realname location description profileurl
@@ -72,16 +65,22 @@ module Flickrie
72
65
  private
73
66
 
74
67
  def initialize(info = {})
68
+ raise ArgumentError if info.nil?
69
+
75
70
  @info = info
76
71
  end
77
72
 
78
73
  def self.from_info(info)
79
- new.get_info(info)
74
+ new.get_info({}, info)
80
75
  end
81
76
 
82
77
  def self.from_find(info)
83
78
  info['username'] = info['username']['_content']
84
79
  new(info)
85
80
  end
81
+
82
+ def self.from_test(info)
83
+ from_find(info)
84
+ end
86
85
  end
87
86
  end
@@ -1,3 +1,3 @@
1
1
  module Flickrie
2
- VERSION = '0.6.1'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -2,21 +2,22 @@ module Flickrie
2
2
  class Video
3
3
  include Media
4
4
 
5
- def ready?; @video['ready'].to_i == 1 if @video['ready'] end
6
- def failed?; @video['failed'].to_i == 1 if @video['failed'] end
7
- def pending?; @video['pending'].to_i == 1 if @video['pending'] end
5
+ def ready?() Integer(@video['ready']) == 1 rescue nil end
6
+ def failed?() Integer(@video['failed']) == 1 rescue nil end
7
+ def pending?() Integer(@video['pending']) == 1 rescue nil end
8
8
 
9
- def duration; @video['duration'].to_i if @video['duration'] end
9
+ def duration() Integer(@video['duration']) rescue nil end
10
10
 
11
- def width; @video['width'].to_i if @video['width'] end
12
- def height; @video['height'].to_i if @video['height'] end
11
+ def width() Integer(@video['width']) rescue nil end
12
+ def height() Integer(@video['height']) rescue nil end
13
13
 
14
- def source_url; @video['source_url'] end
15
- def download_url; @video['download_url'] end
16
- def mobile_download_url; @video['mobile_download_url'] end
14
+ def source_url() @video['source_url'] end
15
+ def download_url() @video['download_url'] end
16
+ def mobile_download_url() @video['mobile_download_url'] end
17
17
 
18
- def get_sizes(info = nil)
19
- info ||= Flickrie.client.get_media_sizes(id).body['sizes']
18
+ def get_sizes(params = {}, info = nil)
19
+ info ||= Flickrie.client.get_media_sizes(id, params).body['sizes']
20
+ @info['usage'] ||= {}
20
21
  @info['usage'].update \
21
22
  'canblog' => info['canblog'],
22
23
  'canprint' => info['canprint'],
@@ -32,7 +33,7 @@ module Flickrie
32
33
  self
33
34
  end
34
35
 
35
- def get_info(info = nil)
36
+ def get_info(params = {}, info = nil)
36
37
  super
37
38
  @video = @info['video']
38
39
 
@@ -0,0 +1,43 @@
1
+ describe Flickrie::ApiMethods do
2
+ it "should have certain methods working" do
3
+ VCR.use_cassette "api_methods/upload_and_delete" do
4
+ media_id = @flickrie.upload(PHOTO_PATH)
5
+ @flickrie.public_media_from_user(USER_NSID).map(&:id).should include(media_id)
6
+ @flickrie.delete_media(media_id)
7
+ @flickrie.public_media_from_user(USER_NSID).map(&:id).should_not include(media_id)
8
+ end
9
+
10
+ VCR.use_cassette "api_methods/asynchronous_upload" do
11
+ ticket_id = @flickrie.upload(PHOTO_PATH, :async => 1)
12
+ begin
13
+ ticket = @flickrie.check_upload_tickets([ticket_id]).first
14
+ end until ticket.complete?
15
+ photo_id = ticket.photo_id
16
+ Flickrie.get_photo_info(photo_id).id.should eq(photo_id)
17
+ @flickrie.delete_photo(photo_id)
18
+ end
19
+
20
+ VCR.use_cassette "api_methods/replace" do
21
+ begin
22
+ id = @flickrie.upload(PHOTO_PATH)
23
+ @flickrie.replace(PHOTO_PATH, id)
24
+ rescue => exception
25
+ exception.code.should eq(1) # Not a pro account
26
+ ensure
27
+ @flickrie.delete_media(id)
28
+ end
29
+ end
30
+
31
+ VCR.use_cassette "api_methods/tags" do
32
+ media = @flickrie.get_media_info(PHOTO_ID)
33
+ tags_before_change = media.tags.join(' ')
34
+ @flickrie.add_media_tags(PHOTO_ID, "janko")
35
+ media.get_info
36
+ media.tags.join(' ').should eq([tags_before_change, "janko"].join(' '))
37
+ tag_id = media.tags.find { |tag| tag.content == "janko" }.id
38
+ @flickrie.remove_media_tag(tag_id)
39
+ media.get_info
40
+ media.tags.join(' ').should eq(tags_before_change)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,32 @@
1
+ describe Flickrie::Error do
2
+ before(:all) do
3
+ Flickrie.api_key = nil
4
+ end
5
+
6
+ context "was raised" do
7
+ use_vcr_cassette "error/was_raised"
8
+
9
+ it "should be raised when the request failed" do
10
+ expect { Flickrie.get_licenses }.to raise_error(described_class)
11
+ expect { Flickrie.upload(PHOTO_PATH) }.to raise_error(described_class)
12
+ end
13
+ end
14
+
15
+ context "code" do
16
+ use_vcr_cassette "error/code"
17
+
18
+ it "should have #code attribute present" do
19
+ begin
20
+ Flickrie.get_licenses
21
+ rescue => exception
22
+ exception.code.should eq(100)
23
+ end
24
+
25
+ begin
26
+ Flickrie.upload(PHOTO_PATH)
27
+ rescue => exception
28
+ exception.code.should eq(100)
29
+ end
30
+ end
31
+ end
32
+ end
File without changes
File without changes
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ describe Flickrie::Instance do
3
+ context "calling api methods" do
4
+ use_vcr_cassette "instance/calling_api_methods"
5
+
6
+ it "should be able to call API methods" do
7
+ # this is to see if the client and upload_client were reset
8
+ Flickrie.get_photo_info(PHOTO_ID)
9
+ Flickrie.access_token = ENV['FLICKR_ACCESS_TOKEN']
10
+ Flickrie.access_secret = ENV['FLICKR_ACCESS_SECRET']
11
+ id = Flickrie.upload(PHOTO_PATH)
12
+ Flickrie.delete_photo(id)
13
+ Flickrie.access_token = Flickrie.access_secret = nil
14
+
15
+ instance = Flickrie::Instance.new(ENV['FLICKR_ACCESS_TOKEN'], ENV['FLICKR_ACCESS_SECRET'])
16
+ user = instance.test_login
17
+ user.username.should eq("Janko Marohnić")
18
+ id = instance.upload(PHOTO_PATH)
19
+ instance.delete_photo(id)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ describe Flickrie::License do
2
+ context "get licenses" do
3
+ use_vcr_cassette "license/get"
4
+
5
+ it "should have all attributes correctly set" do
6
+ licenses = Flickrie.get_licenses
7
+
8
+ licenses.each do |license|
9
+ ('0'..'8').should cover(license.id)
10
+ license.name.should be_an_instance_of(String)
11
+ license.url.should be_an_instance_of(String)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ describe Flickrie::Location do
2
+ context "blank" do
3
+ it "should have all attributes equal to nil" do
4
+ location = Flickrie::Location.public_new
5
+ attributes = location.methods - Object.instance_methods - [:[]]
6
+ attributes.each do |attribute|
7
+ location.send(attribute).should be_nil
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ describe Flickrie::MediaCount do
2
+ context "get" do
3
+ use_vcr_cassette "media_count/get"
4
+
5
+ it "should have correctly set all attributes" do
6
+ dates = [DateTime.parse("1st March 2012"), DateTime.parse("5th May 2012")].map(&:to_time)
7
+ [
8
+ @flickrie.get_media_counts(:taken_dates => dates.join(',')).first,
9
+ @flickrie.get_media_counts(:dates => dates.map(&:to_i).join(',')).first
10
+ ].
11
+ each do |count|
12
+ count.value.should be_an_instance_of(Fixnum)
13
+ count.date_range.begin.should eq(dates.first)
14
+ count.date_range.end.should eq(dates.last)
15
+ end
16
+ end
17
+ end
18
+ end