snapcat 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e888b4d7abb16b802f4805367bb673590c1220a
4
- data.tar.gz: fbb23356c09c30d5544735805a18671afea27ef5
3
+ metadata.gz: ca9e5b503ceac5e5ca3718afb03247f4f4025ad5
4
+ data.tar.gz: 005d1017eb32f3d8e1d52174b77e4c984ab16a5b
5
5
  SHA512:
6
- metadata.gz: aa65c119939ce0e0cc1c2fd4ad27f0a8a2d7f021bde43d38f319da5564cb7b37d330ba89309f314032cbf48f3bf364c1c000367d4d9d807536ae7bc5ac18dc2b
7
- data.tar.gz: 16f5299266b6dc2087998db38f3a342f3c9b331ef3606579c31523c5360fd3c4147cbdfebf30b3c1315e2ceba7bdb7d6166992f7dadd6fa48bf92e2ba9ea1960
6
+ metadata.gz: cd531769fa3d94fc41405dab785056cf51217c3959702cfe74bb534a457126731bc3ab28785fff7174d135c9940c00dcba72a37e784617cd09cd155886364c89
7
+ data.tar.gz: 6e49c51b8b707135607d4103034f42f77286547356ccdec2e433b122000c2bf1e863c05ee404456f54caec8e37e4a5af331a016c9fed5c10feaeb10743dadc2a
@@ -47,7 +47,7 @@ module Snapcat
47
47
 
48
48
  begin
49
49
  file = Tempfile.new(['snap', ".#{file_extension}"])
50
- file.write(encrypted_data)
50
+ file.write(encrypted_data.force_encoding('utf-8'))
51
51
  file.rewind
52
52
 
53
53
  return request_with_username(
@@ -1,5 +1,6 @@
1
1
  module Snapcat
2
2
  class Response
3
+ RECOGNIZED_CONTENT_TYPES = %w(application/json application/octet-stream)
3
4
  attr_reader :code, :data, :http_success
4
5
 
5
6
  def initialize(response, additional_fields = {})
@@ -22,22 +23,28 @@ module Snapcat
22
23
 
23
24
  private
24
25
 
25
- def response_empty?(response)
26
- response.body.to_s.empty?
26
+ def format_recognized_content(content_type, content)
27
+ if content_type == 'application/json'
28
+ JSON.parse(content, symbolize_names: true)
29
+ elsif content_type == 'application/octet-stream'
30
+ { media: Media.new(content) }
31
+ end
27
32
  end
28
33
 
29
34
  def formatted_result(response)
30
- if !response_empty?(response)
31
- if response.content_type == 'application/octet-stream'
32
- { media: Media.new(response.body) }
33
- elsif response.content_type == 'application/json'
34
- JSON.parse(response.body, symbolize_names: true)
35
- else
36
- {}
37
- end
35
+ if !response_empty?(response) && recognized_content_type?(response.content_type)
36
+ format_recognized_content(response.content_type, response.body)
38
37
  else
39
38
  {}
40
39
  end
41
40
  end
41
+
42
+ def recognized_content_type?(content_type)
43
+ RECOGNIZED_CONTENT_TYPES.include? content_type
44
+ end
45
+
46
+ def response_empty?(response)
47
+ response.body.to_s.empty?
48
+ end
42
49
  end
43
50
  end
data/snapcat.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'snapcat'
7
- spec.version = '0.0.1'
7
+ spec.version = '0.0.2'
8
8
  spec.authors = ['Neal Kemp']
9
9
  spec.email = ['']
10
10
  spec.description = %q{Snapchat API wrapper}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neal Kemp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-22 00:00:00.000000000 Z
11
+ date: 2013-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httmultiparty
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
175
  version: '0'
176
176
  requirements: []
177
177
  rubyforge_project:
178
- rubygems_version: 2.0.7
178
+ rubygems_version: 2.0.14
179
179
  signing_key:
180
180
  specification_version: 4
181
181
  summary: Ruby wrapper for Snapchat's private API