contextio 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.textile +29 -0
  2. data/Rakefile +46 -0
  3. data/lib/contextio.rb +104 -0
  4. metadata +58 -0
data/README.textile ADDED
@@ -0,0 +1,29 @@
1
+ h1. Context.IO API Library
2
+
3
+ This repository contains a standalone ruby library for Context.IO. You can
4
+ get more information at "http://context.io":http://context.io. Complete API documentation is available
5
+ at "http://developer.context.io":http://developer.context.io.
6
+
7
+
8
+ h2. LICENSE:
9
+
10
+ Copyright (C) 2011 DokDok Inc.
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in
20
+ all copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
+ THE SOFTWARE.
29
+
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rubygems/specification'
3
+ require 'rake'
4
+ require 'rake/gempackagetask'
5
+
6
+ GEM = "contextio"
7
+ GEM_VERSION = "0.1.0"
8
+ SUMMARY = "Provides interface for Context.io email"
9
+ AUTHOR = "Gary Haran"
10
+ EMAIL = "gary.haran@gmail.com"
11
+ HOMEPAGE = "http://context.io/"
12
+
13
+ task :default => [:test]
14
+
15
+ task :test do
16
+ ruby "spec/contextio_spec.rb"
17
+ end
18
+
19
+ spec = Gem::Specification.new do |s|
20
+ s.name = GEM
21
+ s.version = GEM_VERSION
22
+ s.platform = Gem::Platform::RUBY
23
+ s.summary = SUMMARY
24
+ s.require_paths = ['lib']
25
+ s.files = FileList['app_generators/**/*', 'bin/*', 'lib/**/*.rb', '[A-Z]*'].to_a
26
+
27
+ s.author = AUTHOR
28
+ s.email = EMAIL
29
+ s.homepage = HOMEPAGE
30
+ end
31
+
32
+ Rake::GemPackageTask.new(spec) do |pkg|
33
+ pkg.gem_spec = spec
34
+ end
35
+
36
+ desc "Install the gem locally"
37
+ task :install => [:package] do
38
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
39
+ end
40
+
41
+ desc "Create a gemspec file"
42
+ task :make_spec do
43
+ File.open("#{GEM}.gemspec", "w") do |file|
44
+ file.puts spec.to_ruby
45
+ end
46
+ end
data/lib/contextio.rb ADDED
@@ -0,0 +1,104 @@
1
+ require 'oauth'
2
+ require 'net/http'
3
+
4
+ module ContextIO
5
+ VERSION = "1.0"
6
+
7
+ class ContextIO::Connection
8
+ def initialize(key='', secret='', server='https://api.context.io')
9
+ @consumer = OAuth::Consumer.new(key, secret, {:site => server, :sheme => :header})
10
+ @token = OAuth::AccessToken.new @consumer
11
+ end
12
+
13
+ def all_messages(options)
14
+ get 'allmessages', {:limit => 10, :since => 0}.merge(options)
15
+ end
16
+
17
+ def all_files(options)
18
+ get 'allfiles', {:since => 0}.merge(options)
19
+ end
20
+
21
+ def contact_files(options)
22
+ get 'contactfiles', options
23
+ end
24
+
25
+ def contact_messages(options)
26
+ get 'contactmessages', options
27
+ end
28
+
29
+ def diff_summary(options)
30
+ get 'diffsummary', options
31
+ end
32
+
33
+ def file_search(options)
34
+ get 'filesearch', options
35
+ end
36
+
37
+ def message_info(options)
38
+ get 'messageinfo', options
39
+ end
40
+
41
+ def message_text(options)
42
+ get 'messagetext', options
43
+ end
44
+
45
+ def related_files(options)
46
+ get 'relatedfiles', options
47
+ end
48
+
49
+ def thread_info(options)
50
+ get 'threadinfo', options
51
+ end
52
+
53
+ def search(options)
54
+ get 'search', options
55
+ end
56
+
57
+ def discover(options)
58
+ get 'imap/discover', options
59
+ end
60
+
61
+ def add_account(options)
62
+ get 'imap/addaccount', options
63
+ end
64
+
65
+ def modify_account(options)
66
+ get 'imap/modifyaccount', options
67
+ end
68
+
69
+ def remove_account
70
+ get 'imap/removeaccount'
71
+ end
72
+
73
+ def reset_status
74
+ get 'imap/resetstatus'
75
+ end
76
+
77
+ def download_file(options)
78
+ @token.get "/#{ContextIO::VERSION}/downloadfile?#{parametrize options}"
79
+ end
80
+
81
+ private
82
+
83
+ def url(*args)
84
+ if args.length == 1
85
+ "/#{ContextIO::VERSION}/#{args[0]}.json"
86
+ else
87
+ "/#{ContextIO::VERSION}/#{args.shift.to_s}.json?#{parametrize args.last}"
88
+ end
89
+ end
90
+
91
+ def get(*args)
92
+ @token.get(url(*args), "Accept" => "application/json").body
93
+ end
94
+
95
+ def parametrize(options)
96
+ URI.escape(options.collect do |k,v|
97
+ v = v.to_i if k == :since
98
+ v = v.join(',') if v.instance_of?(Array)
99
+ k = k.to_s.gsub('_', '')
100
+ "#{k}=#{v}"
101
+ end.join('&'))
102
+ end
103
+ end
104
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: contextio
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Gary Haran
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-06 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description:
18
+ email: gary.haran@gmail.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - lib/contextio.rb
27
+ - Rakefile
28
+ - README.textile
29
+ has_rdoc: true
30
+ homepage: http://context.io/
31
+ licenses: []
32
+
33
+ post_install_message:
34
+ rdoc_options: []
35
+
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ requirements: []
51
+
52
+ rubyforge_project:
53
+ rubygems_version: 1.5.1
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Provides interface for Context.io email
57
+ test_files: []
58
+