coop 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby-19mode
@@ -0,0 +1,6 @@
1
+ # Coop! The Ruby gem!
2
+ ## Changelog
3
+
4
+ ### 1.0 (9 March 2012)
5
+
6
+ Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in coop.gemspec
4
+ gemspec
@@ -0,0 +1,5 @@
1
+ guard 'minitest' do
2
+ watch(%r|^test/(.*)\/?test_(.*)\.rb|)
3
+ watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
4
+ watch(%r|^test/test_helper\.rb|) { "test" }
5
+ end
@@ -0,0 +1,56 @@
1
+ # Coop! The Ruby gem! [![Build Status](https://secure.travis-ci.org/evanwalsh/coop.png?branch=master)](http://travis-ci.org/evanwalsh/coop) [![Dependency Status](https://gemnasium.com/evanwalsh/coop.png)](https://gemnasium.com/evanwalsh/coop)
2
+
3
+ Ok, so let's say that you're the kind of person that wants to interact with Co-op via its API.
4
+
5
+ You've come to the right place.
6
+
7
+ ## Installation and setup
8
+
9
+ To install it, just run `gem install coop` from the command line or add `gem 'coop'` to your project's Gemfile.
10
+
11
+ Now, to use it in your code, do this, but substitute in your own Co-op login details:
12
+
13
+ coop = Coop.new("user_email@example.com", "user_password123")
14
+
15
+ That's just the beginning, though.
16
+
17
+ ## Usage
18
+
19
+ With your new Co-op API object, you can access all the API features you'd need.
20
+
21
+ First, you'll need a group object.
22
+
23
+ group = coop.group(12345)
24
+
25
+ ### Statuses
26
+
27
+ That'll give you access to a whole load of stuff. If you want statuses, use this:
28
+
29
+ group.statuses
30
+
31
+ You'll get an object that'll let you use .recent and .where on that to get either the most recent 50 statuses or to get statuses by user or date.
32
+
33
+ group.statuses.recent
34
+ group.statuses.where({ user_id: 54321, date: Date.today })
35
+
36
+ You'll get an array of Coop::Status objects, with all the attributes you'd expect. Cool.
37
+
38
+ Finally, posting a status update is pretty simple.
39
+
40
+ group.post! "This is a status update"
41
+
42
+ Also, you can use `.post_as_cobot!` instead to, well, post as Cobot. Just add another argument with your secret key, like so:
43
+
44
+ group.post_as_cobot! "This is Cobot. Beep boop.", "MySuperSecretAPIKeyFromCoOp"
45
+
46
+ ### Agendas
47
+
48
+ Also, you can mess with the group's agendas API. Try this:
49
+
50
+ group.agenda
51
+
52
+ It returns a Coop::Agenda object, with `.global`, `.users`, `.user`, which will give you the group's agenda, all the user's individual agendas, and the authenticated user's agenda, respectively.
53
+
54
+ ### The rest of the API
55
+
56
+ In further versions of the gem, I'll be implementing the rest of the API. I want to keep it focused, for now. Also, the current Co-op API isn't working completely, so that's another roadblock that should be cleared up soon. I hope.
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ t.test_files = Dir['test/**/*.rb']
9
+ end
10
+
11
+ desc "Run tests"
12
+ task default: :test
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/coop/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Evan Walsh"]
6
+ gem.email = ["evan@nothingconcept.com"]
7
+ gem.description = %q{Interact with the Co-op API with Ruby}
8
+ gem.summary = %q{Interact with the Co-op API with Ruby}
9
+ gem.homepage = "http://github.com/evanwalsh/coop"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "coop"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Coop::VERSION
17
+
18
+ gem.required_ruby_version = '>= 1.9.2'
19
+
20
+ gem.add_development_dependency "rake"
21
+ gem.add_development_dependency "minitest", "~> 2.11.3"
22
+ gem.add_development_dependency "guard-minitest", "~> 0.5.0"
23
+ gem.add_development_dependency "turn", "~> 0.9.3"
24
+ gem.add_development_dependency "webmock", "~> 1.8.2"
25
+
26
+ if RUBY_PLATFORM.downcase.include?("darwin")
27
+ gem.add_development_dependency "growl", "~> 1.0.3"
28
+ end
29
+
30
+ gem.add_dependency "hashie", "~> 1.2.0"
31
+ gem.add_dependency "httparty", "~> 0.8.1"
32
+ gem.add_dependency "json-jruby", "~> 1.5.0" if RUBY_PLATFORM == "java"
33
+ end
@@ -0,0 +1,56 @@
1
+ require 'httparty'
2
+ require 'coop/error'
3
+ require 'coop/api_object'
4
+ require 'coop/session'
5
+ require 'coop/version'
6
+
7
+ module Coop
8
+ include HTTParty
9
+ base_uri 'http://coopapp.com'
10
+ headers "Accept" => "application/json", "User-Agent" => "coop-gem"
11
+
12
+ class << self
13
+ # Public: Shortcut for creating a new Coop::Session for API stuff
14
+ #
15
+ # email - (String) the user's email
16
+ # password - (String) the user's password
17
+ #
18
+ # Examples
19
+ #
20
+ # Coop.new("test@example.com", "password123")
21
+ # # => #<Coop::Session @email="test@example.com">
22
+ #
23
+ # Returns an authenticated Coop::Session object
24
+ def new(email, password)
25
+ basic_auth email, password
26
+ Coop::Session.new(email, password)
27
+ end
28
+
29
+ # Public: Parse an HTTParty response into APIObjects
30
+ #
31
+ # *args - any valid arguments for HTTParty.get
32
+ #
33
+ # Examples
34
+ #
35
+ # Coop.get_parsed("/groups/12345")
36
+ # # => [{"type" => "Note", "users" => ...}]
37
+ #
38
+ # Returns Array of APIObjects or APIObject, depending on response argument
39
+ def get_parsed(*args)
40
+ begin
41
+ request = self.get(*args)
42
+
43
+ raise BadRequest if request.response.code == "400"
44
+ raise Unauthorized if request.response.code == "401"
45
+ raise NotFound if request.response.code == "404"
46
+ raise InternalServerError if request.response.code == "500"
47
+ raise ServiceUnavailable if request.response.code == "503"
48
+
49
+ APIObject.parse_response(request)
50
+
51
+ rescue MultiJson::DecodeError
52
+ nil
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,32 @@
1
+ require 'hashie'
2
+ require 'json'
3
+
4
+ module Coop
5
+ class APIObject < Hashie::Mash
6
+ # Public: Parse an HTTParty Response into a single APIObject or an Array of such
7
+ #
8
+ # response - The HTTParty Response object that will be parsed
9
+ #
10
+ # Examples
11
+ #
12
+ # APIObject.parse_response(HTTParty.get("http://coopapp.com/groups"))
13
+ # # => [{"type" => "Note", "users" => ...}]
14
+ #
15
+ # Returns a singular or array of APIObjects, depending on what it's fed
16
+ def self.parse_response(response)
17
+ response = response.parsed_response.class == String ? JSON.parse(response.parsed_response) : response.parsed_response
18
+ if response.class == Array
19
+ output = Array.new
20
+ response.each do |item|
21
+ output << self.new(item)
22
+ end
23
+ elsif response.class == Hash
24
+ output = self.new(response)
25
+ end
26
+
27
+ output
28
+ end
29
+ end
30
+
31
+ %w(agenda group status user).each{ |o| require "coop/api_object/#{o}" }
32
+ end
@@ -0,0 +1,39 @@
1
+ module Coop
2
+ class Agenda < APIObject
3
+ # Public: Get the group's global agenda
4
+ #
5
+ # Examples
6
+ #
7
+ # Agenda.new({ group_id: 12345 }).global
8
+ # # => #<Coop::APIObject>
9
+ #
10
+ # Returns APIObject with the agenda data
11
+ def global
12
+ Coop.get_parsed("/groups/#{self.group_id}/agenda")
13
+ end
14
+
15
+ # Public: Get the group's agendas for all users
16
+ #
17
+ # Examples
18
+ #
19
+ # Agenda.new({ group_id: 12345 }).users
20
+ # # => [#<Coop::APIObject>, #<Coop::APIObject>, ...]
21
+ #
22
+ # Returns Array of APIObject with the agenda data
23
+ def users
24
+ Coop.get_parsed("/groups/#{self.group_id}/user_agendas")
25
+ end
26
+
27
+ # Public: Get the group's global agenda
28
+ #
29
+ # Examples
30
+ #
31
+ # Agenda.new({ group_id: 12345 }).user
32
+ # # => #<Coop::APIObject>
33
+ #
34
+ # Returns APIObject with the agenda data
35
+ def user
36
+ Coop.get_parsed("/groups/#{self.group_id}/my_agenda")
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,68 @@
1
+ module Coop
2
+ class Group < APIObject
3
+ # Public: The base for all status API calls
4
+ #
5
+ # Examples
6
+ #
7
+ # self.statuses
8
+ # # => #<Coop::Status @group_id=12345>
9
+ #
10
+ # Returns a Coop::Status instance with the group_id set
11
+ def statuses
12
+ Status.new({ group_id: self.id })
13
+ end
14
+
15
+ # Public: Post a status update to a group
16
+ #
17
+ # message - The text for the status update
18
+ #
19
+ # Examples
20
+ #
21
+ # Group.new({ id: 12345 }).post! "Is this computer?"
22
+ # # => "/statuses/123456"
23
+ #
24
+ # Returns String of new status' URL
25
+ def post!(message)
26
+ Status.new({ group_id: self.id }).post!(message)
27
+ end
28
+
29
+ # Public: Post a status update to a group as Cobot
30
+ #
31
+ # message - The text for the status update
32
+ # api_key - The API key needed to post as Cobot
33
+ #
34
+ # Examples
35
+ #
36
+ # Group.new({ id: 12345 }).post_as_cobot! "YES, THIS IS COMPUTER", "THISISMYSECRETKEY"
37
+ # # => "/statuses/123456"
38
+ #
39
+ # Returns String of new status' URL
40
+ def post_as_cobot!(message, api_key)
41
+ Status.new({ group_id: self.id }).post_as_cobot!(message, api_key)
42
+ end
43
+
44
+ # Public: The base for all agenda API calls
45
+ #
46
+ # Examples
47
+ #
48
+ # self.statuses
49
+ # # => #<Coop::Agenda @group_id=12345>
50
+ #
51
+ # Returns a Coop::Agenda instance with the group_id set
52
+ def agenda
53
+ Agenda.new({ group_id: self.id })
54
+ end
55
+
56
+ # Public: The base for all user API calls
57
+ #
58
+ # Examples
59
+ #
60
+ # self.users
61
+ # # => #<Coop::User @group_id=12345>
62
+ #
63
+ # Returns a Coop::User instance with the group_id set
64
+ def users
65
+ User.new({ group_id: self.id }).all
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,120 @@
1
+ module Coop
2
+ class Status < APIObject
3
+ # Public: Get a group's 50 most recent tweets
4
+ #
5
+ # Examples
6
+ #
7
+ # Status.new({ group_id: 12345 }).recent
8
+ # # => [{"type" => "Note", "users" => ...}]
9
+ #
10
+ # Returns an Array of statuses as APIObjects
11
+ def recent
12
+ Coop.get_parsed("/groups/#{self.group_id}/statuses")
13
+ end
14
+
15
+ # Public: Post a status update to a group
16
+ #
17
+ # message - The text for the status update
18
+ #
19
+ # Examples
20
+ #
21
+ # Status.new({ group_id: 12345 }).post! "Is this computer?"
22
+ # # => "/statuses/123456"
23
+ #
24
+ # Returns String of new status' URL
25
+ def post!(message)
26
+ Coop.post(
27
+ "/groups/#{self.group_id}/statuses",
28
+ query: { status: message },
29
+ headers: { "Accept" => "application/xml" }
30
+ ).headers["Location"]
31
+ end
32
+
33
+ # Public: Post a status update to a group as Cobot
34
+ #
35
+ # message - The text for the status update
36
+ # api_key - The API key needed to post as Cobot
37
+ #
38
+ # Examples
39
+ #
40
+ # Status.new({ group_id: 12345 }).post_as_cobot! "YES, THIS IS COMPUTER", "THISISMYSECRETKEY"
41
+ # # => "/statuses/123456"
42
+ #
43
+ # Returns String of new status' URL
44
+ def post_as_cobot!(message, api_key)
45
+ Coop.post(
46
+ "/groups/#{self.group_id}/statuses",
47
+ query: { status: message, key: api_key },
48
+ headers: { "Accept" => "application/xml" }
49
+ ).headers["Location"]
50
+ end
51
+
52
+ # Public: A poor man's Arel for querying the status API
53
+ #
54
+ # options - A hash of options, which can include either or both of:
55
+ # user_id => the id of the user
56
+ # date => a Date object
57
+ #
58
+ # Examples
59
+ #
60
+ # Status.new({ group_id: 12345 }).where({ user_id: 12345, date: Date.today })
61
+ #
62
+ # Returns Array of APIObjects
63
+ def where(options = {})
64
+ if options[:user_id] && options[:date]
65
+ where_user_and_date(options[:user_id], options[:date])
66
+ elsif options[:user_id]
67
+ where_user(options[:user_id])
68
+ elsif options[:date]
69
+ where_date(options[:date])
70
+ else
71
+ recent
72
+ end
73
+ end
74
+
75
+ # Private: Get statuses for user on a date
76
+ #
77
+ # user_id - the user's id
78
+ # date - the Date object
79
+ #
80
+ # Examples
81
+ #
82
+ # where_user_and_date(12345, Date.today)
83
+ #
84
+ # Returns Array of APIObjects
85
+ def where_user_and_date(user_id, date)
86
+ date = Date.parse(date.to_s).strftime("%Y%m%d")
87
+ Coop.get_parsed("/groups/#{self.group_id}/users/#{user_id}/#{date}")
88
+ end
89
+ private :where_user_and_date
90
+
91
+ # Private: Get statuses for user on a date
92
+ #
93
+ # user_id - the user's id
94
+ #
95
+ # Examples
96
+ #
97
+ # where_user(12345)
98
+ #
99
+ # Returns Array of APIObjects
100
+ def where_user(user_id)
101
+ Coop.get_parsed("/groups/#{self.group_id}/users/#{user_id}")
102
+ end
103
+ private :where_user
104
+
105
+ # Private: Get statuses for user on a date
106
+ #
107
+ # date - the Date object
108
+ #
109
+ # Examples
110
+ #
111
+ # where_date(Date.today)
112
+ #
113
+ # Returns Array of APIObjects
114
+ def where_date(date)
115
+ date = Date.parse(date.to_s).strftime("%Y%m%d")
116
+ Coop.get_parsed("/groups/#{self.group_id}/#{date}")
117
+ end
118
+ private :where_date
119
+ end
120
+ end
@@ -0,0 +1,29 @@
1
+ module Coop
2
+ class User < APIObject
3
+ # Public: List of a group's users with all info
4
+ #
5
+ # Examples
6
+ #
7
+ # User.new({ group_id: 12345 }).all
8
+ # # => [#<Coop::APIObject>, #<Coop::APIObject>, ...]
9
+ #
10
+ # Returns Array of APIObjects with user data
11
+ def all
12
+ Coop.get_parsed("/group/#{self.group_id}/users")
13
+ end
14
+
15
+ # Public: User data for one user
16
+ #
17
+ # id - The user's id
18
+ #
19
+ # Examples
20
+ #
21
+ # User.find(12345)
22
+ # # => #<Coop::APIObject>
23
+ #
24
+ # Returns APIObject with user data
25
+ def self.find(id)
26
+ Coop.get_parsed("/users/#{id}")
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ module Coop
2
+ # Standard class for errors
3
+ class Error < StandardError; end
4
+
5
+ # Raised when Co-op returns the HTTP status code 400
6
+ class BadRequest < Error; end
7
+
8
+ # Raised when Co-op returns the HTTP status code 401
9
+ class Unauthorized < Error; end
10
+
11
+ # Raised when Co-op returns the HTTP status code 404
12
+ class NotFound < Error; end
13
+
14
+ # Raised when Co-op returns the HTTP status code 500
15
+ class InternalServerError < Error; end
16
+
17
+ # Raised when Co-op returns the HTTP status code 503
18
+ class ServiceUnavailable < Error; end
19
+ end
@@ -0,0 +1,51 @@
1
+ module Coop
2
+ class Session
3
+ attr_accessor :email
4
+
5
+ # Public: Creates a new API session
6
+ #
7
+ # email - (String) the user's email
8
+ # password - (String) the user's password
9
+ #
10
+ # Examples
11
+ #
12
+ # Coop::Session.new("test@example.com", "password123")
13
+ # # => #<Coop::Session @email="test@example.com">
14
+ #
15
+ # Returns a Coop::Session instance
16
+ def initialize(email, password)
17
+ @email = email
18
+ password = password
19
+ end
20
+
21
+ # Public: Creates a Coop::Group object
22
+ #
23
+ # id - (Fixnum) the group id (as found in the app URL: http://coopapp.com/groups/[group_id])
24
+ #
25
+ # Examples
26
+ #
27
+ # session.group(12345)
28
+ # # => #<Coop::Group @id=12345>
29
+ #
30
+ # Returns a Coop::Group instance
31
+ def group(id)
32
+ Coop::Group.new({
33
+ id: id
34
+ })
35
+ end
36
+
37
+ # Public: Creates a Coop::Group object
38
+ #
39
+ # id - (Fixnum) the group id (as found in the app URL: http://coopapp.com/groups/[group_id]/users/[user_id])
40
+ #
41
+ # Examples
42
+ #
43
+ # session.user(12345)
44
+ # # => #<Coop::User @id=12345>
45
+ #
46
+ # Returns a Coop::User instance
47
+ def user(id)
48
+ Coop::User.find(id)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module Coop
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+
3
+ class TestAgenda < MiniTest::Unit::TestCase
4
+ def setup
5
+ @coop = Coop.new("test@example.com", "password")
6
+ @agenda = Coop::Agenda.new({ group_id: 12345 })
7
+ end
8
+
9
+ def test_new_object
10
+ assert_instance_of Coop::Agenda, @agenda
11
+ end
12
+
13
+ def test_global
14
+ stub_get("/groups/12345/agenda").with({
15
+ headers: { 'Accept' => 'application/json' }
16
+ }).to_return({
17
+ body: fixture('agenda.json')
18
+ })
19
+
20
+ assert_instance_of Coop::APIObject, @agenda.global
21
+ end
22
+
23
+ def test_users
24
+ stub_get("/groups/12345/user_agendas").with({
25
+ headers: { 'Accept' => 'application/json' }
26
+ }).to_return({
27
+ body: fixture('user_agendas.json')
28
+ })
29
+
30
+ assert_instance_of Array, @agenda.users
31
+ end
32
+
33
+ def test_user
34
+ stub_get("/groups/12345/my_agenda").with({
35
+ headers: { 'Accept' => 'application/json' }
36
+ }).to_return({
37
+ body: fixture('my_agenda.json')
38
+ })
39
+
40
+ assert_instance_of Coop::APIObject, @agenda.user
41
+ end
42
+ end
@@ -0,0 +1,50 @@
1
+ require 'test_helper'
2
+
3
+ class TestGroup < MiniTest::Unit::TestCase
4
+ def setup
5
+ @coop = Coop.new("test@example.com", "password")
6
+ @group = @coop.group(12345)
7
+ end
8
+
9
+ def test_new_object
10
+ assert_instance_of Coop::Group, Coop::Group.new
11
+ end
12
+
13
+ def test_session_proxy
14
+ assert_instance_of Coop::Group, @group
15
+ end
16
+
17
+ def test_statuses
18
+ assert_instance_of Coop::Status, @group.statuses
19
+ end
20
+
21
+ def test_set_group_id_on_status
22
+ assert_equal @group.statuses.group_id, @group.id
23
+ end
24
+
25
+ def test_post
26
+ stub_post("/groups/#{@group.id}/statuses").with({
27
+ headers: { 'Accept' => 'application/xml' },
28
+ query: { status: "Testing update" }
29
+ }).to_return({
30
+ headers: { 'Location' => '/statuses/123456' }
31
+ })
32
+
33
+ assert_equal "/statuses/123456", @group.post!("Testing update")
34
+ end
35
+
36
+ def test_post_as_cobot
37
+ stub_post("/groups/12345/statuses").with({
38
+ headers: { 'Accept' => 'application/xml' },
39
+ query: { key: "BeepBoopAPIKeyGoesHere", status: "Testing update as Cobot" }
40
+ }).to_return({
41
+ headers: { 'Location' => '/statuses/123456' }
42
+ })
43
+
44
+ assert_equal "/statuses/123456", @group.post_as_cobot!("Testing update as Cobot", "BeepBoopAPIKeyGoesHere")
45
+ end
46
+
47
+ def test_agenda
48
+ assert_instance_of Coop::Agenda, @group.agenda
49
+ end
50
+ end
@@ -0,0 +1,79 @@
1
+ require 'test_helper'
2
+
3
+ class TestStatus < MiniTest::Unit::TestCase
4
+ def setup
5
+ @coop = Coop.new("test@example.com", "password")
6
+ @group = @coop.group(12345)
7
+ @status = Coop::Status.new({ group_id: 12345 })
8
+ end
9
+
10
+ def test_new_object
11
+ assert_instance_of Coop::Status, @status
12
+ end
13
+
14
+ def test_group_id_access
15
+ assert_equal @status.group_id, 12345
16
+ end
17
+
18
+ def test_post
19
+ stub_post("/groups/#{@group.id}/statuses").with({
20
+ headers: { 'Accept' => 'application/xml' },
21
+ query: { status: "Testing update" }
22
+ }).to_return({
23
+ headers: { 'Location' => '/statuses/123456' }
24
+ })
25
+
26
+ assert_equal "/statuses/123456", @status.post!("Testing update")
27
+ end
28
+
29
+ def test_post_as_cobot
30
+ stub_post("/groups/12345/statuses").with({
31
+ headers: { 'Accept' => 'application/xml' },
32
+ query: { key: "BeepBoopAPIKeyGoesHere", status: "Testing update as Cobot" }
33
+ }).to_return({
34
+ headers: { 'Location' => '/statuses/123456' }
35
+ })
36
+
37
+ assert_equal "/statuses/123456", @status.post_as_cobot!("Testing update as Cobot", "BeepBoopAPIKeyGoesHere")
38
+ end
39
+
40
+ def test_recent
41
+ stub_get("/groups/12345/statuses").with({
42
+ headers: { 'Accept' => 'application/json' }
43
+ }).to_return({
44
+ body: fixture('statuses.json')
45
+ })
46
+
47
+ assert_instance_of Array, @status.recent
48
+ end
49
+
50
+ def test_where_user
51
+ stub_get("/groups/12345/users/12345").with({
52
+ headers: { 'Accept' => 'application/json' }
53
+ }).to_return({
54
+ body: fixture('statuses_for_user.json')
55
+ })
56
+
57
+ assert_instance_of Array, @status.where({ user_id: 12345 })
58
+ end
59
+
60
+ def test_where_date
61
+ stub_get("/groups/12345/20120303").with({
62
+ headers: { 'Accept' => 'application/json' }
63
+ }).to_return({
64
+ body: fixture('statuses_for_user.json')
65
+ })
66
+
67
+ assert_instance_of Array, @status.where({ date: Date.new(2012, 03, 03) })
68
+ end
69
+
70
+ def test_where_user_and_date
71
+ stub_get("/groups/12345/users/12345/20120303").with({
72
+ headers: { 'Accept' => 'application/json' }
73
+ }).to_return({
74
+ body: fixture('statuses_for_user.json')
75
+ })
76
+
77
+ assert_instance_of Array, @status.where({ user_id: 12345, date: Date.new(2012, 03, 03) })
78
+ end
79
+ end
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ class TestUser < MiniTest::Unit::TestCase
4
+ def setup
5
+ @coop = Coop.new("test@example.com", "password")
6
+ @user = Coop::User.new({ group_id: 12345 })
7
+ end
8
+
9
+ def test_new_object
10
+ assert_instance_of Coop::User, @user
11
+ end
12
+
13
+ def test_all
14
+ stub_get("/group/12345/users").with({
15
+ headers: { 'Accept' => 'application/json' }
16
+ }).to_return({
17
+ body: fixture('users.json')
18
+ })
19
+
20
+ assert_instance_of Array, @user.all
21
+ end
22
+
23
+ def test_find
24
+ stub_get("/users/12345").with({
25
+ headers: { 'Accept' => 'application/json' }
26
+ }).to_return({
27
+ body: fixture('user.json')
28
+ })
29
+
30
+ assert_instance_of Coop::APIObject, Coop::User.find(12345)
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ class TestAPIObject < MiniTest::Unit::TestCase
4
+ def setup
5
+ @object = Coop::APIObject.new({
6
+ test: true,
7
+ name: "object",
8
+ value: "APIObject",
9
+ arbitrary_key: "this"
10
+ })
11
+ end
12
+
13
+ def test_new
14
+ assert_instance_of Coop::APIObject, @object
15
+ end
16
+
17
+ def test_mash
18
+ assert_equal true, @object.test
19
+ assert_equal "object", @object.name
20
+ assert_equal "APIObject", @object.value
21
+ assert_equal "this", @object.arbitrary_key
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ class TestSession < MiniTest::Unit::TestCase
4
+ def setup
5
+ @coop = Coop.new("test@example.com", "password")
6
+ end
7
+
8
+ def test_new_is_session
9
+ assert_instance_of Coop::Session, @coop
10
+ end
11
+
12
+ def test_group
13
+ @group = @coop.group(12345)
14
+ assert_instance_of Coop::Group, @group
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ {"agenda_html":"<p>This is an agenda</p>","group_id":12345,"agenda":"This is an agenda"}
@@ -0,0 +1 @@
1
+ {"agenda_html":"<ul>\n\t<li>Bacon slap</li>\n\t<li>Bacon slap</li>\n\t<li>Bacon slap</li>\n\t<li>Bacon slap</li>\n</ul>","user_id":12345,"agenda":"* Bacon slap\n* Bacon slap\n* Bacon slap\n* Bacon slap"}
@@ -0,0 +1 @@
1
+ {"updated_at":"2012-03-02T22:51:00-05:00","created_at":"2012-03-02T22:51:00-05:00","group_id":12561,"text":"This is an image URL: http://i.imgur.com/vgiiq.jpg","user":{"name":"Evan Walsh","email":"evan@massivedanger.com","avatar_thumb_url":"http://coopapp.com/uploads/avatars/24105/thumb/9-m.png?1330884227","id":12345},"type":"Note","id":916273}
@@ -0,0 +1 @@
1
+ [{"updated_at":"2012-03-02T22:51:00-05:00","created_at":"2012-03-02T22:51:00-05:00","group_id":12345,"text":"This is an image URL: http://i.imgur.com/vgiiq.jpg","user":{"name":"Evan Walsh","email":"evan@massivedanger.com","avatar_thumb_url":"http://coopapp.com/uploads/avatars/12345/thumb/9-m.png?1330791782","id":12345},"type":"Note","id":916273},{"updated_at":"2012-03-02T22:50:15-05:00","created_at":"2012-03-02T22:50:15-05:00","group_id":12345,"text":"This is a test post on Co-op","user":{"name":"Evan Walsh","email":"evan@massivedanger.com","avatar_thumb_url":"http://coopapp.com/uploads/avatars/12345/thumb/9-m.png?1330791782","id":12345},"type":"Note","id":916271}]
@@ -0,0 +1 @@
1
+ [{"updated_at":"2012-03-03T12:00:42-05:00","created_at":"2012-03-03T12:00:42-05:00","group_id":12345,"text":"Bacon slap","user":{"name":"Evan Walsh","email":"evan@massivedanger.com","avatar_thumb_url":"http://coopapp.com/uploads/avatars/12345/thumb/9-m.png?1330791782","id":12345},"type":"Note","id":916410}]
@@ -0,0 +1 @@
1
+ [{"updated_at":"2012-03-03T12:00:42-05:00","group_id":12345,"text":"Bacon slap","id":916410,"created_at":"2012-03-03T12:00:42-05:00","user":{"avatar_thumb_url":"http://coopapp.com/uploads/avatars/12345/thumb/9-m.png?1330791782","name":"Evan Walsh","email":"evan@massivedanger.com","id":12345},"type":"Note"},{"updated_at":"2012-03-02T22:51:00-05:00","group_id":12345,"text":"This is an image URL: http://i.imgur.com/vgiiq.jpg","id":916273,"created_at":"2012-03-02T22:51:00-05:00","user":{"avatar_thumb_url":"http://coopapp.com/uploads/avatars/12345/thumb/9-m.png?1330791782","name":"Evan Walsh","email":"evan@massivedanger.com","id":12345},"type":"Note"},{"updated_at":"2012-03-02T22:50:15-05:00","group_id":12345,"text":"This is a test post on Co-op","id":916271,"created_at":"2012-03-02T22:50:15-05:00","user":{"avatar_thumb_url":"http://coopapp.com/uploads/avatars/12345/thumb/9-m.png?1330791782","name":"Evan Walsh","email":"evan@massivedanger.com","id":12345},"type":"Note"}]
@@ -0,0 +1 @@
1
+ [{"updated_at":"2012-03-03T12:00:42-05:00","created_at":"2012-03-03T12:00:42-05:00","group_id":12345,"text":"Bacon slap","user":{"name":"Evan Walsh","email":"evan@massivedanger.com","avatar_thumb_url":"http://coopapp.com/uploads/avatars/12345/thumb/9-m.png?1330791782","id":12345},"type":"Note","id":916410}]
@@ -0,0 +1 @@
1
+ {"created_at":"2012-03-02T19:39:35-08:00","first_name":"Evan","updated_at":"2012-03-03T08:23:02-08:00","email":"evan@massivedanger.com","avatar_thumb_url":"http://coopapp.com/uploads/avatars/12345/thumb/9-m.png?1330791782","last_name":"Walsh","city":null,"has_harvest_credential":false,"id":12345}
@@ -0,0 +1 @@
1
+ [{"agenda_html":"<p>- Bacon slap<br />\n- Bacon slap<br />\n- Bacon slap<br />\n- Bacon slap</p>","user_id":12345,"agenda":"- Bacon slap\n- Bacon slap\n- Bacon slap\n- Bacon slap"}]
@@ -0,0 +1 @@
1
+ [{"city":null,"email":"evan@massivedanger.com","first_name":"Evan","id":24105,"last_name":"Walsh","updated_at":"2012-03-08T20:55:33-05:00","avatar_thumb_url":"http://coopapp.com/uploads/avatars/24105/thumb/9-m.png?1331258133"}]
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class TestCoop < MiniTest::Unit::TestCase
4
+ def setup
5
+ @coop = Coop.new("test@example.com", "password")
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ require 'minitest/autorun'
2
+ require 'turn/autorun'
3
+ require 'webmock/test_unit'
4
+ require 'coop'
5
+
6
+ include WebMock::API
7
+ stub_request(:any, Coop.base_uri)
8
+
9
+ def fixture(file)
10
+ File.read(File.join(Dir.pwd, 'test', 'fixtures', file))
11
+ end
12
+
13
+ def auth_path(path)
14
+ "http://test%40example.com:password@coopapp.com#{path}"
15
+ end
16
+
17
+ def stub_delete(path)
18
+ stub_request(:delete, auth_path(path))
19
+ end
20
+
21
+ def stub_get(path)
22
+ stub_request(:get, auth_path(path))
23
+ end
24
+
25
+ def stub_post(path)
26
+ stub_request(:post, auth_path(path))
27
+ end
28
+
29
+ def stub_put(path)
30
+ stub_request(:put, auth_path(path))
31
+ end
32
+
33
+ # WebMock.after_request do |request_signature, response|
34
+ # puts "Request #{request_signature} was made and #{response} was returned"
35
+ # end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coop
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Evan Walsh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70193356449620 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70193356449620
25
+ - !ruby/object:Gem::Dependency
26
+ name: minitest
27
+ requirement: &70193356449080 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.11.3
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70193356449080
36
+ - !ruby/object:Gem::Dependency
37
+ name: guard-minitest
38
+ requirement: &70193356448580 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.5.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70193356448580
47
+ - !ruby/object:Gem::Dependency
48
+ name: turn
49
+ requirement: &70193356448120 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.3
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70193356448120
58
+ - !ruby/object:Gem::Dependency
59
+ name: webmock
60
+ requirement: &70193356447660 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.8.2
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70193356447660
69
+ - !ruby/object:Gem::Dependency
70
+ name: growl
71
+ requirement: &70193356447160 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.0.3
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70193356447160
80
+ - !ruby/object:Gem::Dependency
81
+ name: hashie
82
+ requirement: &70193356446700 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 1.2.0
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: *70193356446700
91
+ - !ruby/object:Gem::Dependency
92
+ name: httparty
93
+ requirement: &70193356446240 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: 0.8.1
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: *70193356446240
102
+ description: Interact with the Co-op API with Ruby
103
+ email:
104
+ - evan@nothingconcept.com
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - .gitignore
110
+ - .travis.yml
111
+ - CHANGELOG.md
112
+ - Gemfile
113
+ - Guardfile
114
+ - README.md
115
+ - Rakefile
116
+ - coop.gemspec
117
+ - lib/coop.rb
118
+ - lib/coop/api_object.rb
119
+ - lib/coop/api_object/agenda.rb
120
+ - lib/coop/api_object/group.rb
121
+ - lib/coop/api_object/status.rb
122
+ - lib/coop/api_object/user.rb
123
+ - lib/coop/error.rb
124
+ - lib/coop/session.rb
125
+ - lib/coop/version.rb
126
+ - test/coop/api_object/test_agenda.rb
127
+ - test/coop/api_object/test_group.rb
128
+ - test/coop/api_object/test_status.rb
129
+ - test/coop/api_object/test_user.rb
130
+ - test/coop/test_api_object.rb
131
+ - test/coop/test_session.rb
132
+ - test/fixtures/agenda.json
133
+ - test/fixtures/my_agenda.json
134
+ - test/fixtures/show_status.json
135
+ - test/fixtures/statuses.json
136
+ - test/fixtures/statuses_for_date.json
137
+ - test/fixtures/statuses_for_user.json
138
+ - test/fixtures/statuses_for_user_and_date.json
139
+ - test/fixtures/user.json
140
+ - test/fixtures/user_agendas.json
141
+ - test/fixtures/users.json
142
+ - test/test_coop.rb
143
+ - test/test_helper.rb
144
+ homepage: http://github.com/evanwalsh/coop
145
+ licenses: []
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: 1.9.2
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 1.8.11
165
+ signing_key:
166
+ specification_version: 3
167
+ summary: Interact with the Co-op API with Ruby
168
+ test_files:
169
+ - test/coop/api_object/test_agenda.rb
170
+ - test/coop/api_object/test_group.rb
171
+ - test/coop/api_object/test_status.rb
172
+ - test/coop/api_object/test_user.rb
173
+ - test/coop/test_api_object.rb
174
+ - test/coop/test_session.rb
175
+ - test/fixtures/agenda.json
176
+ - test/fixtures/my_agenda.json
177
+ - test/fixtures/show_status.json
178
+ - test/fixtures/statuses.json
179
+ - test/fixtures/statuses_for_date.json
180
+ - test/fixtures/statuses_for_user.json
181
+ - test/fixtures/statuses_for_user_and_date.json
182
+ - test/fixtures/user.json
183
+ - test/fixtures/user_agendas.json
184
+ - test/fixtures/users.json
185
+ - test/test_coop.rb
186
+ - test/test_helper.rb
187
+ has_rdoc: