socialcastr 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,9 +8,9 @@ Socialcastr.configuration do |config|
8
8
  config.domain = "domain"
9
9
  end
10
10
 
11
- xml = File.read("/Users/bru/Desktop/socialcast.xml")
11
+ xml = File.read("~/Download/socialcast.xml")
12
12
  start_time = Time.new
13
- messages = Socialcastr::Message.parse(xml)
13
+ messages = Socialcastr::Message.parse_collection(xml)
14
14
  end_time = Time.new
15
15
 
16
16
  puts "Found #{messages.count} messages in #{end_time - start_time} seconds"
@@ -103,6 +103,9 @@ module Socialcastr
103
103
  url = URI.parse(@endpoint)
104
104
  https = Net::HTTP.new(url.host, url.port)
105
105
  https.verify_mode = OpenSSL::SSL::VERIFY_NONE
106
+ if @debug
107
+ https.set_debug_output $stderr
108
+ end
106
109
  https.use_ssl = true
107
110
  return https
108
111
  end
@@ -87,13 +87,15 @@ module Socialcastr
87
87
  end
88
88
 
89
89
  def find_single(id, options)
90
- path = element_path(id, options)
91
- parse(api.get(path))
90
+ (prefix_options, query_options) = parse_options(options)
91
+ path = element_path(id, prefix_options)
92
+ parse(api.get(path, query_options))
92
93
  end
93
94
 
94
95
  def find_every(options)
95
- path = collection_path(options)
96
- parse_collection(api.get(path))
96
+ (prefix_options, query_options) = parse_options(options)
97
+ path = collection_path(prefix_options)
98
+ parse_collection(api.get(path, query_options))
97
99
  end
98
100
 
99
101
  def all(*arguments)
@@ -109,7 +111,7 @@ module Socialcastr
109
111
  end
110
112
 
111
113
  def element_path(id, prefix_options = {})
112
- "#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}"
114
+ "#{collection_path(prefix_options)}/#{URI.escape id.to_s}"
113
115
  end
114
116
 
115
117
  def collection_path(options = {})
@@ -120,6 +122,17 @@ module Socialcastr
120
122
  options.map { |k,v| k.to_s.gsub("_id", 's') + "/" + v.to_s }.join("/") + "/"
121
123
  end
122
124
 
125
+ def parse_options(options)
126
+ prefix_options = {}
127
+ options.each_pair do |k,v|
128
+ if k.to_s.match(/_id$/)
129
+ prefix_options[k] = v
130
+ options.delete(k)
131
+ end
132
+ end
133
+ return [prefix_options, options]
134
+ end
135
+
123
136
  def model_name
124
137
  self.to_s.gsub(/^.*::/, '')
125
138
  end
@@ -11,7 +11,7 @@ module Socialcastr
11
11
  element :thumbnail_url
12
12
  element :url
13
13
  element :likes_count
14
- element :created_at
14
+ element :"created-at", :as => :created_at
15
15
  element :id
16
16
 
17
17
  def unlikable_by?(api_id)
@@ -3,7 +3,7 @@ module Socialcastr
3
3
  id_element
4
4
  element :unlikable
5
5
  element :user, :class => Socialcastr::User
6
- element :created_at
6
+ element :"created-at", :as => :created_at
7
7
  def unlikable_by?(api_id)
8
8
  @unlikable && api_id == self.user_id ? true : false
9
9
  end
@@ -10,8 +10,8 @@ module Socialcastr
10
10
  element :external_url
11
11
  element :icon
12
12
  element :likable
13
- element :created_at
14
- element :updated_at
13
+ element "created-at", :as => :created_at
14
+ element "updated-at", :as => :updated_at
15
15
  element :last_interacted_at
16
16
  element :player_url
17
17
  element :thumbnail_url
@@ -1,3 +1,3 @@
1
1
  module Socialcastr
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/socialcastr.rb CHANGED
@@ -30,11 +30,19 @@ module Socialcastr
30
30
 
31
31
  class Configuration
32
32
  include Singleton
33
- ATTRIBUTES = [:domain, :username, :password, :config_file]
33
+ ATTRIBUTES = [:domain, :username, :password, :format, :debug, :config_file]
34
34
  attr_accessor *ATTRIBUTES
35
35
 
36
36
  def ready?
37
- [@domain, @username, @password].map(&:nil?).none?
37
+ (ATTRIBUTES - [:config_file]).map { |a| self.send a }.map(&:nil?).none?
38
+ end
39
+
40
+ def format
41
+ @format ||= 'xml'
42
+ end
43
+
44
+ def debug
45
+ @debug ||= false
38
46
  end
39
47
 
40
48
  def reset
@@ -53,6 +61,8 @@ module Socialcastr
53
61
  Configuration.instance.domain = config['domain']
54
62
  Configuration.instance.username = config['username']
55
63
  Configuration.instance.password = config['password']
64
+ Configuration.instance.format = config['format']
65
+ Configuration.instance.debug = config['debug']
56
66
  end
57
67
  end
58
68
  Configuration.instance
@@ -61,7 +71,7 @@ module Socialcastr
61
71
  def self.api
62
72
  config = Configuration.instance
63
73
  raise MissingConfiguration unless config.username
64
- API.new(config.username, config.password, config.domain)
74
+ API.new(config.username, config.password, config.domain, config.format, config.debug)
65
75
  end
66
76
 
67
77
  end
data/spec/message_spec.rb CHANGED
@@ -165,7 +165,7 @@ describe Socialcastr::Message do
165
165
  @api = mock(:api)
166
166
  response = "<comment></comment>"
167
167
  Socialcastr::Message.stub!(:api).and_return(@api)
168
- @api.should_receive(:post).with("/messages/425/comments", {:text => "hallo world"}).and_return(response)
168
+ @api.should_receive(:post).with("/messages/425/comments", {"comment[text]" => "hallo world"}).and_return(response)
169
169
  @message.comment! :text => "hallo world"
170
170
  end
171
171
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socialcastr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Riccardo Cambiassi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-10 00:00:00 +01:00
18
+ date: 2011-05-16 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency