socialcast-api 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in socialcast-api.gemspec
4
+ gemspec
data/README ADDED
@@ -0,0 +1,43 @@
1
+ First off I am not affiliated with Socialcast the company in any way.
2
+
3
+ SocialcastAPI is a ruby interface to the RESTful API provided by Socialcast.com
4
+ for interacting with their services as outlined here:
5
+
6
+ http://www.socialcast.com/resources/api.html
7
+
8
+ Here I am implementing it using the ActiveResource library
9
+
10
+ http://api.rubyonrails.org/classes/ActiveResource/Base.html
11
+
12
+ which supports dynamically generating Ruby objects from the XML or JSON
13
+ structures returned from the calls to the web services. At this point it is
14
+ mostly functional, I haven't really started playing with the attachments portion
15
+ yet so don't expect that to work at the moment. I need to add a lot of
16
+ documentation and examples though. That's probably the next big thing to be
17
+ done.
18
+
19
+ # Post a new message to your general purpose stream
20
+ Message.new(:body => 'This was sent via the API')
21
+
22
+ # Find the user named John Smith
23
+ User.search(:q => 'john smith').first
24
+
25
+ # List the top 10 users who have posted the most #worklogs
26
+ users = Hash.new(0)
27
+
28
+ Message.search_all_pages(:q => '#worklog').each do |message|
29
+ users[message.user.name] += 1
30
+ end
31
+
32
+ users.sort {|a,b| a[1] <=> b[1]}.reverse.first(10).each {|user| puts "#{user[0]}: #{user[1]}"}
33
+
34
+ # Print count of all users in the community
35
+ puts User.all_pages.count
36
+
37
+ # Print all users name and url
38
+ User.all_pages.each_with_index do |user, index|
39
+ puts "#{index}: #{user.name} - #{user.url}"
40
+ end
41
+
42
+ More examples to come.
43
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,26 @@
1
+ require 'active_resource'
2
+ require 'singleton'
3
+ require 'yaml'
4
+
5
+ module SocialcastApi
6
+ class Configuration
7
+ include Singleton
8
+ ATTRIBUTES = [:site, :user, :password, :config_file]
9
+ attr_accessor *ATTRIBUTES
10
+ end
11
+
12
+ def self.configuration
13
+ if block_given?
14
+ yield Configuration.instance
15
+ if Configuration.config_file
16
+ config = YAML::load_file(Configuration.config_file)
17
+ Configuration.site = config['site']
18
+ Configuration.user = config['user']
19
+ Configuration.password = config['password']
20
+ end
21
+ require 'socialcast-api/base'
22
+ end
23
+ Configuration.instance
24
+ end
25
+
26
+ end
@@ -0,0 +1,150 @@
1
+ module SocialcastApi
2
+ class Base < ActiveResource::Base
3
+ self.site = SocialcastApi.configuration.site
4
+ self.user = SocialcastApi.configuration.user
5
+ self.password = SocialcastApi.configuration.password
6
+ end
7
+
8
+ class Message < Base
9
+
10
+ class Like < Base
11
+ self.site = Message.site.to_s + "messages/:message_id/"
12
+ end
13
+
14
+ class Flag < Base
15
+ self.site = Message.site.to_s + "messages/:message_id/"
16
+ end
17
+
18
+ def self.search(args = {})
19
+ get(:search, args).map {|message| Message.new(message)}
20
+ end
21
+
22
+ def self.search_all_pages(args = {})
23
+ results = Array.new
24
+ page = 1
25
+ per_page = 500
26
+
27
+ begin
28
+ messages = get(:search, :page => page, :per_page => per_page, :q => args[:q]).map {|message| Message.new(message)}
29
+ page += 1
30
+ results += messages
31
+ end until messages.count < per_page
32
+
33
+ return results
34
+ end
35
+
36
+ def like
37
+ Message.post(id.to_s + '/likes')
38
+ end
39
+
40
+ def unlike
41
+ likedbyme = likes.select {|alike| alike.unlikable}.first
42
+ if likedbyme
43
+ likedbyme.prefix_options = {:message_id => self.id}
44
+ likedbyme.destroy
45
+ end
46
+ end
47
+
48
+ def flag
49
+ Message.post(id.to_s + '/flags')
50
+ end
51
+
52
+ def unflag
53
+ Message.delete(id.to_s + '/flags/' + attributes[:flag].id)
54
+ end
55
+
56
+ end
57
+
58
+ class Comment < Base
59
+
60
+ self.site = Message.site.to_s + "messages/:message_id/"
61
+
62
+ class Like < Base
63
+ self.site = Comment.site.to_s + "comments/:comment_id/"
64
+ end
65
+
66
+ def like
67
+ Comment.post(id.to_s + '/likes')
68
+ end
69
+
70
+ def unlike
71
+ likedbyme = likes.select {|alike| alike.unlikable}.first
72
+ if likedbyme
73
+ likedbyme.prefix_options = {:message_id => message_id, :comment_id => self.id}
74
+ likedbyme.destroy
75
+ end
76
+ end
77
+
78
+ end
79
+
80
+ class User < Base
81
+
82
+ def self.search(args = {})
83
+ get(:search, args).map {|user| User.new(user)}
84
+ end
85
+
86
+ def messages
87
+ get(:messages).map {|message| Message.new(message)}
88
+ end
89
+
90
+ def followers(args = {})
91
+ get(:followers, args).map {|follower| User.new(follower)}
92
+ end
93
+
94
+ def follow
95
+ User.post(id.to_s + '/followers')
96
+ end
97
+
98
+ def unfollow
99
+ delete('followers/' + contact_id.to_s)
100
+ end
101
+
102
+ def following(args = {})
103
+ get(:following, args).map {|user| User.new(user)}
104
+ end
105
+
106
+ def self.all_pages
107
+ results = Array.new
108
+ page = 1
109
+ per_page = 500
110
+
111
+ begin
112
+ users = all(:params => {:page => page, :per_page => per_page})
113
+ page += 1
114
+ results += users
115
+ end until users.count < per_page
116
+
117
+ return results
118
+ end
119
+
120
+ end
121
+
122
+ class Stream < Base
123
+
124
+ def messages(args = {})
125
+ get(:messages, args).map {|message| Message.new(message)}
126
+ end
127
+
128
+ end
129
+
130
+ class Group < Base
131
+
132
+ def members(args = {})
133
+ get(:members, args).map {|member| User.new(member)}
134
+ end
135
+
136
+ end
137
+
138
+ class GroupMembership < Base
139
+ end
140
+
141
+ class Category < Base
142
+ end
143
+
144
+ class ContentFilter < Base
145
+ end
146
+
147
+ # This class is not working or tested yet, just a frame!
148
+ class Attachment < Base
149
+ end
150
+ end
@@ -0,0 +1,5 @@
1
+ module Socialcast
2
+ module Api
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "socialcast-api/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "socialcast-api"
7
+ s.version = Socialcast::Api::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Matthew Closson", "Sean Cashin"]
10
+ s.email = ["matthew.closson@gmail.com", "scashin133@gmail.com"]
11
+ s.homepage = "http://github.com/mclosson/socialcast-api"
12
+ s.summary = %q{Socialcast API Interface and Examples}
13
+ s.description = %q{Socialcast API Interface and Examples}
14
+
15
+ s.rubyforge_project = "scashin133-socialcast-api"
16
+ s.add_runtime_dependency(%q<activeresource>, [">= 2.3"])
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
data/socialcast.yml ADDED
@@ -0,0 +1,3 @@
1
+ user: your_email_address
2
+ password: your_socialcast_password
3
+ subdomain: your_socialcast_subdomain
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: socialcast-api
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Matthew Closson
13
+ - Sean Cashin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-27 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activeresource
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 2
31
+ - 3
32
+ version: "2.3"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: Socialcast API Interface and Examples
36
+ email:
37
+ - matthew.closson@gmail.com
38
+ - scashin133@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - .gitignore
47
+ - Gemfile
48
+ - README
49
+ - Rakefile
50
+ - lib/socialcast-api.rb
51
+ - lib/socialcast-api/base.rb
52
+ - lib/socialcast-api/version.rb
53
+ - socialcast-api.gemspec
54
+ - socialcast.yml
55
+ has_rdoc: true
56
+ homepage: http://github.com/mclosson/socialcast-api
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ requirements: []
81
+
82
+ rubyforge_project: scashin133-socialcast-api
83
+ rubygems_version: 1.3.7
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Socialcast API Interface and Examples
87
+ test_files: []
88
+