smugmugapi 0.9.0 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,4 +1,14 @@
1
+ == 0.9.2 / 2007-12-04
2
+
3
+ * Fixed "automatic" URL endpoint for 1.2.1 api
4
+ * Added gzip support on http transport
5
+ * Added sftp backup utility
6
+
7
+ == 0.9.1 / 2007-12-03
8
+
9
+ * Fixed a bug in xmlstruct processing
10
+ of "special" ids (ending in URL, etc)
11
+
1
12
  == 0.9.0 / 2007-12-03
2
13
 
3
14
  * Initial public release
4
-
data/lib/smugmug/core.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require "rexml/document"
2
2
  require "uri"
3
3
  require "net/https"
4
+ require "zlib"
5
+
6
+ require "pp" if $DEBUG
4
7
 
5
8
  class SmugMugAPI
6
9
  class << self
@@ -21,7 +24,13 @@ class SmugMugAPI
21
24
  end
22
25
 
23
26
  def api_path
24
- @url || "api.smugmug.com/hack/rest/#{api_version}/"
27
+ if @url
28
+ @url
29
+ elsif api_version == '1.2.1'
30
+ "api.smugmug.com/services/api/rest/#{api_version}/"
31
+ else
32
+ "api.smugmug.com/hack/rest/#{api_version}/"
33
+ end
25
34
  end
26
35
 
27
36
  def agent
@@ -44,7 +53,10 @@ class SmugMugAPI
44
53
  url = transport + "://" + api_path + "?" +
45
54
  params.map { |k,v| URI.encode("#{SmugMugAPI.camelize(k)}=#{v}") }.join("&")
46
55
  uri = URI.parse(url)
47
- headers['User-Agent'] = agent
56
+ headers['User-Agent'] ||= agent
57
+ headers['Accept-Encoding'] ||= 'gzip, deflate'
58
+
59
+ pp [:smugapi, params, headers, uri] if $DEBUG
48
60
 
49
61
  http = Net::HTTP.new(uri.host, uri.port)
50
62
  if transport == 'https'
@@ -60,9 +72,20 @@ class SmugMugAPI
60
72
  def parse_response(response)
61
73
  puts "HTTP #{response.code}: #{response.message}" if $DEBUG
62
74
 
63
- raise SmugMugAPI::Error.new("HTTP #{response.code} on #{url}") unless response.code.to_i == 200
75
+ raise SmugMugAPI::Error.new("HTTP #{response.code}") unless response.code.to_i == 200
76
+
77
+ body = case response['content-encoding']
78
+ when 'gzip'
79
+ Zlib::GzipReader.new(StringIO.new(response.body)).read
80
+ when 'deflate'
81
+ Zlib::Inflate.inflate(response.body)
82
+ when nil
83
+ response.body
84
+ else
85
+ raise "Unknown encoding #{response['content-encoding']}"
86
+ end
64
87
 
65
- doc = REXML::Document.new(response.body)
88
+ doc = REXML::Document.new(body)
66
89
  if doc.root.attributes['stat'] != 'ok'
67
90
  err = doc.root.elements['/rsp/err']
68
91
  code = err.attributes['code']
@@ -81,7 +104,7 @@ class SmugMugAPI
81
104
  call(params, 'http')
82
105
  end
83
106
 
84
- def call(params={}, transport = "http")
107
+ def call(params = {}, transport = "http")
85
108
  parse_response(get(params, {}, transport))
86
109
  end
87
110
  end
@@ -22,10 +22,7 @@ class SmugMugAPI
22
22
  when Fixnum
23
23
  key
24
24
  else
25
- key = XMLStruct.camalize(key)
26
- key = key.gsub(/ID$/i, "ID")
27
- key = key.gsub(/EXIF/i, "EXIF")
28
- key.gsub(/X(.?)Large/i) { "X#{$1}Large" }
25
+ SmugMugAPI.camelize(key)
29
26
  end
30
27
  end
31
28
 
@@ -37,6 +34,7 @@ class SmugMugAPI
37
34
  result
38
35
  else
39
36
  # key = XMLStruct.attrib_key(attrib)
37
+ # puts "Searching for #{key}"
40
38
  @xml.attributes[XMLStruct.attrib_key(attrib)]
41
39
  end
42
40
  end
@@ -68,7 +66,7 @@ class SmugMugAPI
68
66
  end
69
67
 
70
68
  def method_missing(*args)
71
- method = XMLStruct.camalize(args.shift)
69
+ method = SmugMugAPI.camelize(args.shift)
72
70
  path = "#{method}"
73
71
  if node = @xml.elements[path]
74
72
  XMLStruct.new(node)
@@ -77,10 +75,6 @@ class SmugMugAPI
77
75
  end
78
76
  end
79
77
 
80
- def self.camalize(str)
81
- str.to_s.gsub(/(^|_)(.)/) { $2.upcase }
82
- end
83
-
84
78
  def to_s
85
79
  @xml.to_s
86
80
  end
data/lib/smugmugapi.rb CHANGED
@@ -6,7 +6,7 @@ require File.join(File.dirname(__FILE__), "smugmug/upload")
6
6
  require File.join(File.dirname(__FILE__), "smugmug/logon")
7
7
 
8
8
  class SmugMugAPI
9
- VERSION = "0.9.0"
9
+ VERSION = "0.9.2"
10
10
 
11
11
  def initialize(base="smugmug")
12
12
  @base = base
data.tar.gz.sig CHANGED
@@ -1,2 +1,5 @@
1
- 2�e�3�鲌Ǡ��2#�v���r���8ܖz��1����C���z��<OWa+��@�ɥ�XH�# b�\���|JZ�x������4��QN���u���VԸ�"��7� I&���9��ؿ�޾����J����)�G���)��ݿ
2
- ø�b$#ٞ� ����l+�8!�U��-t:��� 7w��K���r���(=L�+�
1
+ ���3 s�$
2
+ *P
3
+ 9�{!�4��\
4
+ (�L*�m��N�xl���eX3�5#g�R��8��� ��� ����"��W���]��o�ި5��%�F'P�O벋z�6^X��:���w�U��gT���ɦ!�R�� �'@�^#Fb| .
5
+ ��"���d��;�,�ܡ�*ޝ�*dx�S��Z/L!���ʬ��R�TY����^��%�M/c�Ż�P��P!�C*�t���/V�<�O{y
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: smugmugapi
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.9.0
7
- date: 2007-12-03 00:00:00 -05:00
6
+ version: 0.9.2
7
+ date: 2007-12-05 00:00:00 -05:00
8
8
  summary: A very light wrapper around the SmugMug REST API
9
9
  require_paths:
10
10
  - lib
metadata.gz.sig CHANGED
Binary file