gram 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create use ruby-1.9.2@gram
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :gemcutter
2
+
3
+ gemspec
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gram (0.0.1)
5
+ rest-client
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.1.2)
11
+ mime-types (1.16)
12
+ rest-client (1.6.1)
13
+ mime-types (>= 1.16)
14
+ rspec (2.5.0)
15
+ rspec-core (~> 2.5.0)
16
+ rspec-expectations (~> 2.5.0)
17
+ rspec-mocks (~> 2.5.0)
18
+ rspec-core (2.5.1)
19
+ rspec-expectations (2.5.0)
20
+ diff-lcs (~> 1.1.2)
21
+ rspec-mocks (2.5.0)
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ bundler (~> 1.0.7)
28
+ gram!
29
+ rest-client
30
+ rspec (~> 2.5.0)
@@ -0,0 +1,8 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ desc "Run the specs under spec"
6
+ RSpec::Core::RakeTask.new
7
+
8
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ #gram
2
+
3
+ Gram is an internal administration tool for Codegram.
4
+
5
+ It is composed of independent components. For now the only available component is Blog. To install and setup Gram, just do the following:
6
+
7
+ $ echo "token: MY_CODEGRAM_TOKEN" > ~/.gramrc
8
+ $ gem install gram
9
+
10
+ ##Blog component
11
+
12
+ To publish a blogpost, type this:
13
+
14
+ $ gram blog my_blogpost.markdown
15
+
16
+ The `my_blogpost.markdown` file should be a regular markdown file with some headers in it, like this:
17
+
18
+ ---
19
+ title: My blog post title
20
+ tagline: Stranger than fiction
21
+ ---
22
+
23
+ # My awesome header
24
+ ## More markdown goodness, etc.
25
+
26
+ ## Copyright
27
+
28
+ Copyright (c) 2011 Codegram. See LICENSE for details.
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ $: << 'lib'
3
+ require 'gram'
4
+
5
+ component = ARGV.shift
6
+ args = ARGV
7
+
8
+ raise "Unknown Gram component. Available components are: #{Gram::COMPONENTS.join(', ')}" unless Gram::COMPONENTS.include?(component)
9
+
10
+ eval("Gram::#{component.capitalize}").run(*args)
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "gram/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "gram"
7
+ s.version = Gram::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Josep M. Bach", "Josep Jaume Rey", "Oriol Gual"]
10
+ s.email = ["info@codegram.com"]
11
+ s.homepage = "http://github.com/codegram/gram"
12
+ s.summary = %q{Internal client for Codegram administration}
13
+ s.description = %q{Internal client for Codegram administration}
14
+
15
+ s.rubyforge_project = "gram"
16
+
17
+ s.add_runtime_dependency 'rest-client'
18
+
19
+ s.add_development_dependency 'bundler', '~> 1.0.7'
20
+ s.add_development_dependency 'rspec', '~> 2.5.0'
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ["lib"]
26
+ end
@@ -0,0 +1,6 @@
1
+ require 'gram/blog'
2
+ require 'gram/blog/parser'
3
+
4
+ module Gram
5
+ COMPONENTS = %w(blog)
6
+ end
@@ -0,0 +1,30 @@
1
+ require 'rest-client'
2
+
3
+ module Gram
4
+ module Blog
5
+ class << self
6
+
7
+ def run(*args)
8
+ file = args.first
9
+ raise "File #{file} does not exist." unless File.exists?(file)
10
+ puts "Gram::Blog posting..."
11
+ post = Parser.parse(file)
12
+ response = RestClient.post("http://codegram.com/api/posts", token: get_token, post: post )
13
+ puts "Response Code: #{response.code}"
14
+ puts "Response Body: #{response.body}"
15
+ end
16
+
17
+ private
18
+
19
+ def get_token
20
+ if File.exists?(File.join(File.expand_path('~'), '.gramrc'))
21
+ YAML.load(File.read(File.join(File.expand_path('~'), '.gramrc')))["token"]
22
+ else
23
+ puts "Can't get Gram token. Please create a ~/.gramrc YAML file with a token key."
24
+ exit(1)
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,24 @@
1
+ require 'yaml'
2
+
3
+ module Gram
4
+ module Blog
5
+ module Parser
6
+ class << self
7
+
8
+ def parse(file)
9
+ raw_content = File.read(file)
10
+ headers = raw_content.match(/---(.*)---/m)
11
+ yaml = YAML.load($1.strip)
12
+
13
+ title = yaml["title"]
14
+ tagline = yaml["tagline"]
15
+
16
+ content = raw_content.gsub(/---.*---/m, '').strip
17
+
18
+ { title: title, tagline: tagline, body: content }
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Gram
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ module Gram
4
+ module Blog
5
+ describe Parser do
6
+
7
+ describe ".parse" do
8
+ it 'converts a file into a hash' do
9
+ file = double :file
10
+ raw = """
11
+ ---
12
+ title: My title
13
+ tagline: My tagline
14
+ ---
15
+
16
+ #My post
17
+ #
18
+ Blah
19
+ """
20
+ File.stub(:read).with(file).and_return raw
21
+
22
+ subject.parse(file).should == { title: 'My title',
23
+ tagline: 'My tagline',
24
+ body: "#My post\n#\nBlah"}
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ module Gram
4
+ describe Blog do
5
+
6
+ before do
7
+ File.stub(:exists?).and_return true
8
+ end
9
+
10
+ describe ".run" do
11
+ it 'parses the file' do
12
+ subject::Parser.should_receive(:parse).with("my_post.md")
13
+ expect {
14
+ subject.run("my_post.md")
15
+ }.to raise_error(RestClient::InternalServerError)
16
+ end
17
+ it 'sends a post request' do
18
+ post = double :post
19
+ token = double :token
20
+ response = double :response, code: 201, body: 'ok'
21
+ subject.stub(:get_token).and_return token
22
+ subject::Parser.stub(:parse).with("my_post.md").and_return post
23
+
24
+ RestClient.should_receive(:post).with("http://codegram.com/api/posts", token: token, post: post).and_return response
25
+
26
+ subject.run("my_post.md")
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gram do
4
+ end
@@ -0,0 +1,2 @@
1
+ require 'rspec'
2
+ require 'gram'
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gram
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
+ - Josep M. Bach
13
+ - Josep Jaume Rey
14
+ - Oriol Gual
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-02-23 00:00:00 +01:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rest-client
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 1
45
+ - 0
46
+ - 7
47
+ version: 1.0.7
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rspec
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 2
60
+ - 5
61
+ - 0
62
+ version: 2.5.0
63
+ type: :development
64
+ version_requirements: *id003
65
+ description: Internal client for Codegram administration
66
+ email:
67
+ - info@codegram.com
68
+ executables:
69
+ - gram
70
+ extensions: []
71
+
72
+ extra_rdoc_files: []
73
+
74
+ files:
75
+ - .rspec
76
+ - .rvmrc
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - Rakefile
80
+ - Readme.md
81
+ - bin/gram
82
+ - gram.gemspec
83
+ - lib/gram.rb
84
+ - lib/gram/blog.rb
85
+ - lib/gram/blog/parser.rb
86
+ - lib/gram/version.rb
87
+ - spec/gram/blog/parser_spec.rb
88
+ - spec/gram/blog_spec.rb
89
+ - spec/gram_spec.rb
90
+ - spec/spec_helper.rb
91
+ has_rdoc: true
92
+ homepage: http://github.com/codegram/gram
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options: []
97
+
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ requirements: []
117
+
118
+ rubyforge_project: gram
119
+ rubygems_version: 1.3.7
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Internal client for Codegram administration
123
+ test_files:
124
+ - spec/gram/blog/parser_spec.rb
125
+ - spec/gram/blog_spec.rb
126
+ - spec/gram_spec.rb
127
+ - spec/spec_helper.rb