soup-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +34 -0
  3. data/Rakefile +54 -0
  4. data/ext/soup/soup.cr +133 -0
  5. data/lib/soup/version.rb +6 -0
  6. metadata +66 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b6f79d07024077398f62ac29da32e2d358ae063
4
+ data.tar.gz: 94da43e7166aeda83d6f10f9bd3bddc01347f1bd
5
+ SHA512:
6
+ metadata.gz: d0ee1db8550bf30b6dba97cfe8ef168415ef5869f8f74665f1e23fb7f23985b54dde1b3dc675660f85f0ef3b502ea228a8e8382757b745fdcb16272acb06f015
7
+ data.tar.gz: 23d36e2112e3814e676b6a5604418f402cf3fa9ae8350e52ad689a01ce487ab72d4f2309222488d6145eae84550dee37959b949c184184bf03759778fa654611
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ LibSoup bindings
2
+ ================
3
+
4
+ Requires
5
+ --------
6
+ * rubber-generate >= 0.0.15
7
+ * ruby-gnome2 (including development files)
8
+ * libsoup-2.4 (including development files)
9
+
10
+ Description
11
+ -----------
12
+
13
+ Basic bindings for using the libsoup library from Ruby.
14
+
15
+ e.g
16
+
17
+ require 'gtk2'
18
+ require 'soup'
19
+ require 'digest/md5'
20
+
21
+ session = Soup::SessionAsync.new
22
+
23
+ message = Soup::Message.new("GET", "http://www.google.com/")
24
+
25
+ session.queue(message) do |*args|
26
+ puts message.response_body
27
+
28
+ Gtk.main_quit
29
+
30
+ false
31
+ end
32
+
33
+ Gtk.main
34
+
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ gem 'rake-compiler'
3
+ require 'rake/extensiontask'
4
+ BASE_DIR = Dir.pwd
5
+ require 'rubygems/package_task'
6
+ require 'rake/testtask'
7
+
8
+ $: << './lib'
9
+
10
+ require 'soup/version'
11
+ exts = []
12
+
13
+ namespace :prepare do
14
+ FileList["ext/*/*.cr"].each do |cr|
15
+ dir = File.dirname(cr)
16
+ name = File.basename(dir)
17
+ desc "Generate source for #{name}"
18
+ task(name.intern) do
19
+ sh 'rubber-generate', '--build-dir', dir, cr
20
+ end
21
+ end
22
+ end
23
+
24
+ spec = Gem::Specification.new do |s|
25
+ s.name = "soup-ruby"
26
+ s.author = "Geoff Youngs"
27
+ s.email = "git@intersect-uk.co.uk"
28
+ s.version = Soup::BINDINGS_VERSION
29
+ s.homepage = "http://github.com/geoffyoungs/soup-ruby"
30
+ s.summary = "Soup bindings using rubber-generate"
31
+ s.add_dependency("rubber-generate", ">= 0.0.17")
32
+ s.platform = Gem::Platform::RUBY
33
+ s.extensions = FileList["ext/*/extconf.rb"]
34
+ s.files = FileList['ext/*/*.{c,h,cr,rd}'] + ['Rakefile', 'README.md'] + FileList['lib/**/*.rb']
35
+ s.description = <<-EOF
36
+ Libsoup bindings for ruby. Partial coverage sufficient to allow HTTP requests to be handled without blocking the mainloop.
37
+
38
+ e.g
39
+ require 'gtk2'
40
+ require 'soup'
41
+
42
+ EOF
43
+ end
44
+ Gem::PackageTask.new(spec) do |pkg|
45
+ pkg.need_tar = true
46
+ end
47
+ Rake::ExtensionTask.new("soup", spec)
48
+
49
+ Rake::TestTask.new do |t|
50
+ t.test_files = FileList['test/*_test.rb']
51
+ end
52
+
53
+ task :default, :compile
54
+
data/ext/soup/soup.cr ADDED
@@ -0,0 +1,133 @@
1
+ %pkg-config gtk+-2.0
2
+ %pkg-config libsoup-2.4
3
+ %name soup
4
+
5
+ %{
6
+ #include <intern.h>
7
+
8
+ #define INIT(obj, gobj) __my_init(obj, G_OBJECT(gobj))
9
+
10
+ static inline void __my_init(VALUE obj, GObject *gobj) {
11
+ g_object_ref(gobj);
12
+ g_object_ref_sink(gobj);
13
+ G_INITIALIZE(obj, gobj);
14
+ }
15
+
16
+ static inline VALUE strOrNil(const char *str) {
17
+ if (str) {
18
+ return rb_str_new2(str);
19
+ } else {
20
+ return Qnil;
21
+ }
22
+ }
23
+
24
+ static void queue_callback(SoupSession *session, SoupMessage *message, gpointer user_data) {
25
+ VALUE block = (VALUE)user_data;
26
+ volatile VALUE ary = rb_ary_new3(2, GOBJ2RVAL(session), GOBJ2RVAL(message));
27
+ if (RTEST(rb_proc_call(block, ary))) {
28
+ // Truthy - requeue
29
+ soup_session_requeue_message(session, message);
30
+ } else {
31
+ RUBYFUNC_DEL(block);
32
+ }
33
+ }
34
+
35
+ static void each_header(const char *name, const char *value, gpointer user_data) {
36
+ VALUE block = (VALUE)user_data;
37
+ volatile VALUE ary = rb_ary_new3(2, rb_str_new2(name), rb_str_new2(value));
38
+ rb_proc_call(block, ary);
39
+ }
40
+
41
+ %}
42
+
43
+ %include libsoup/soup.h
44
+
45
+ %map strOrNil > VALUE : strOrNil(%%)
46
+
47
+ module Soup
48
+ gcpool RubyFunc
49
+
50
+ gobject Session < SOUP_TYPE_SESSION
51
+ @type SoupSession
52
+ def queue(SoupMessage *message)
53
+ if (rb_block_given_p()) {
54
+ VALUE block = rb_block_proc();
55
+ RUBYFUNC_ADD(block);
56
+ soup_session_queue_message(_self, message, queue_callback, (void*)block);
57
+ } else {
58
+ soup_session_queue_message(_self, message, NULL, NULL);
59
+ }
60
+ end
61
+
62
+ def guint:send(SoupMessage *msg)
63
+ return soup_session_send_message(_self, msg);
64
+ end
65
+
66
+ def pause(SoupMessage *msg)
67
+ soup_session_pause_message(_self, msg);
68
+ end
69
+
70
+ def unpause(SoupMessage *msg)
71
+ soup_session_unpause_message(_self, msg);
72
+ end
73
+
74
+ def abort
75
+ soup_session_abort(_self);
76
+ end
77
+ end
78
+
79
+ gobject SessionAsync < SOUP_TYPE_SESSION_ASYNC
80
+ @type SoupAsyncSession
81
+ def initialize()
82
+ INIT(self, soup_session_async_new());
83
+ end
84
+ end
85
+
86
+ gboxed URI < SOUP_TYPE_URI
87
+ @type SoupURI
88
+ def initialize(char * uri_string)
89
+ INIT(self, soup_uri_new(uri_string));
90
+ end
91
+ def char*:to_s
92
+ return soup_uri_to_string(_self, FALSE);
93
+ end
94
+ end
95
+
96
+ gobject Message < SOUP_TYPE_MESSAGE
97
+ @type SoupMessage
98
+ def initialize(char * method, char * uri)
99
+ INIT(self, soup_message_new(method, uri));
100
+ end
101
+
102
+ def set_request_header(char *name, char *value)
103
+ soup_message_headers_replace(_self->request_headers, name, value);
104
+ end
105
+
106
+ def unset_request_header(char *name)
107
+ soup_message_headers_remove(_self->request_headers, name);
108
+ end
109
+
110
+ def set_request_body(char *type, T_STRING body)
111
+ soup_message_set_request(_self, type, SOUP_MEMORY_COPY, RSTRING_PTR(body), RSTRING_LEN(body));
112
+ end
113
+
114
+ def char *:get_response_header(char *name)
115
+ return soup_message_headers_get_one(_self->response_headers, name);
116
+ end
117
+
118
+ def each_response_header
119
+ VALUE block = rb_block_proc();
120
+ rb_need_block();
121
+ soup_message_headers_foreach(_self->response_headers, each_header, (gpointer)block);
122
+ end
123
+
124
+ def response_body
125
+ SoupBuffer *buffer = soup_message_body_flatten(_self->response_body);
126
+ volatile VALUE str = rb_str_new(buffer->data, buffer->length);
127
+
128
+ soup_buffer_free(buffer);
129
+ return str;
130
+ end
131
+ end
132
+ end
133
+
@@ -0,0 +1,6 @@
1
+ module Soup
2
+ BINDINGS_VERSION= [0,0,1]
3
+ def BINDINGS_VERSION.to_s
4
+ join('.')
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soup-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Geoff Youngs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubber-generate
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.17
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.17
27
+ description: |+
28
+ Libsoup bindings for ruby. Partial coverage sufficient to allow HTTP requests to be handled without blocking the mainloop.
29
+
30
+ e.g
31
+ require 'gtk2'
32
+ require 'soup'
33
+
34
+ email: git@intersect-uk.co.uk
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - ext/soup/soup.cr
40
+ - Rakefile
41
+ - README.md
42
+ - lib/soup/version.rb
43
+ homepage: http://github.com/geoffyoungs/soup-ruby
44
+ licenses: []
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.0.0.rc.2
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Soup bindings using rubber-generate
66
+ test_files: []